Hi
I'm fairly new to Formidable forms, but I have creted a form and it all works fine. I'd like to add a couple of hidden fields and I'd like these to contain the value of some PHP SESSION variables I have set up.
How can I assign these values to form fields so they are passed in the email that is sent as a result of the form being submitted.
Thanks
Welcome to Formidable. There are a few ways of doing it, though I think the easiest is to use a Formidable hook. Since you want the value set _before_ the notification is sent, you'll want to use frm_pre_create_entry and/or frm_pre_update_entry. In the hook, you'll retireve your session values and set the hidden field values.
Hi Rob. Thanks for the suggestions. frm_pre_create_entry looks like a good option. I tried this codeadd_filter('frm_pre_create_entry', 'utm_source');function utm_source($values) { if ( $values['form_id'] == 1 ) { $values['item_meta'][12] = $_SESSION["utm_source"]; } return $values;
}
but it doesn't do anything and I'm certain there is a value in the session variable.
Is this filter registered? Do I need to do that? Is there something here I'm missing?
Thanks
Roger
When you edit the entry in the backend, do you see the value in the hidden field? Filters don't need to be registered. As long as your form id is 1 and your hidden field id is 12, it should've worked. You can install a WP Debug plugin and make sure the code is being run and doing what you want.
When I look at the HTML of the web page, the value of the hidden field is empty, which is how it's defined in the Formidable forms plugin. input type="hidden" id="field_z5zoc" name="item_meta[12]" value="". The form itself has input type="hidden" name="form_id" value="1". In my functions.php, this is what I have set up...add_filter('frm_pre_create_entry', 'utm_source', 10, 2);
function utm_source($values) {
if ( $values['form_id'] == 1 ) { $values['item_meta'][12] = "test value"; // $values['item_meta'][12] = $_SESSION["utm_source"]; }
return $values;
}I can't see why this is not working! Unless the filter is not available in the free version of the plugin.I'd be grateful for any suggestions or alternatives.Thanks
My question is about editing the entry in the backend and seeing if there's a value stored for that field. Go to the form's entries and edit the entry you created after putting your code in. Also, install a Debug Log - Manager Tool, put an error_log statement in your function, and within seconds, you'll know if it's even hitting that code. I don't know if hooks are only available in certain versions.
I've added a default value of "none" to the hidden field and this shows up on the form (in the HTML) and on the submitted form email.I can't get the filter to work - it seems to do nothingI have cleared the cache again and again, but no change.I installed a debug log manager at your suggestion and added error_log statements in my code. There doesn't seem to be any issue there.Are there any alternatives to achieve what I'd like to do? Is it possible to set the value of a field to the result of a shortcode, for instance?
I just implemented the same thing as a test (except I used a hardcoded value "test value" instead of a session variable), and it works as expected. The value is saved in the entry and is shown in the notification. At this point, you'll need to either continue to work with it, using the debugger to see what's not happening, or hire a developer to help you get to the bottom of it. https://formidable-masterminds.com/developers-directory/
Please login or Register to submit your answer