I would like to add a hidden input field to a gravity form like:
<input type="hidden" name="Campaign_ID" value="ABCD"> where "ABCD" is a value that can be changed in the Gravity form interface.
Any tips / ideas
Thanks!
2 Answers
Have you tried adding a Hidden Field via the Gravity Form interface? Hidden is one of the field types you can add via the Standard Fields box.
I just made a field, and it generated this:
<input name="input_10" type="hidden" value="ABCD"> Unfortunately, I do not see a way to change the name, id, or class of the field, but you can set a label (which appears to do nothing) and value, and set the value to be dynamically generated.
Here is an article about the Hidden field in Gravity Form's Documentation:
1In gravity form, you can add the hidden field using the form design page from Standard Fields. There is no need to add html code for that, gravity form will add the field code to your form. If you want to assign the value of the hidden field to a static one, you can enter the value from in the Default Value of the hidden field from advanced tab. You can also utilize the Merge Tags to make the hidden filed value dynamic. For example, you could add {ip} merge tags if you want to make the value of the hidden field to be the user's IP address.
If you need to change the value based on user input from other fields (or anything else), then you can add PHP code that controls that.
let's assume the form ID is: 1, and the hidden filed id is 14, and you would like to change the value of the hidden filed based on the value of filed number 5. The following code should be added to the functions.php file of your active theme.
add_action( 'gform_pre_submission_1', 'pre_submission_handler' ); function pre_submission_handler( $form ) { if ($_POST['input_5'] == 'ABCD'){ $_POST['input_14'] = 'Value 1'; } else{ $_POST['input_14'] = 'Value 2'; } } You can read more about the gform_pre_submission from this page.