PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

add hidden input

  1. I have a javascript to add a hidden input field to a form, but I'd rather use a hook. I need to be able to set name, id and value of the input. This is for tracking only, so GF retaining value is not necessary, only something that should be read on submission.
    Any ideas?

    Posted 12 years ago on Friday January 20, 2012 | Permalink
  2. Hi, Melanie_D,

    Take a look at the "gform_field_input" and "gform_field_content" hooks.

    http://www.gravityhelp.com/documentation/page/Gform_field_input
    http://www.gravityhelp.com/documentation/page/Gform_field_content

    With those hooks you are able to take a field on your form and completely change it. So you could have a hidden field on your form and then recreate the field's <input> tag.

    Below is an example where I took my hidden tracker field (field 11) on my form (form id 23) and rebuilt the tag:

    add_action("gform_field_input", "tracker", 10, 5);
    function tracker($input, $field, $value, $lead_id, $form_id)
    {
    	if ($form_id == 23 && $field["id"] == 11)
    	{
    		$input = '<input type="hidden" id="hidTracker" name="hidTracker" value="test">';
    		return $input;
    	}
    }

    When that runs, the HTML has my new version of the tag.

    Posted 12 years ago on Friday February 3, 2012 | Permalink

This topic has been resolved and has been closed to new replies.