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.

Pass a variable to the form via $_POST

  1. So that's basically what I'm trying to do and from the pre-sales language it looks like I should be able to do it but I can't find any instructions (I'm smart so if they exist point me to them ;o) or other posts in the forum about it.

    I have a mini-form that I set up that posts to the page with the gravity form and I have the values of 3 form fields I'm trying to pass. Let's just talk about First name and Last name.

    I have under "Advanced" on the name field, in the Field Parameter Name boxes the following-

    $_POST['first_name']
    $_POST['last_name']

    And my form is-

    <form id="short_form" action="http://foo.com/subscribe" method="post">
    <ul class="form_row">
                	<li class="form_label">First Name</li>
                    <li class="form_field"><input type="text" name="first_name" size="20" value="" /></li>
                </ul>
                <ul class="form_row">
                	<li class="form_label">Last Name</li>
                    <li class="form_field"><input type="text" name="last_name" size="20" value="" /></li>
                </ul>
                <ul class="form_row">
                	<li class="form_label">Email Address</li>
                    <li class="form_field"><input type="text" name="email" size="20" value="" /></li>
                </ul>
                <ul class="form_row">
                	<li class="form_label">&nbsp;</li>
                    <li class="form_field"><input type="submit" value="Submit" name="submit" /></li>
                </ul>
    </form>

    Am I missing something here? When I get to my gravity form onsubmit of this form, the gravity form fields are blank.

    Thanks!

    Posted 9 years ago on Tuesday March 16, 2010 | Permalink
  2. Gravity Forms fields are not automatically pre-populated via a post.

    They can be pre-populated either by PHP using an API hook or by passing data to them via query string and turning on dynamic field population.

    You would either have to add some PHP to take advantage of available API hooks to the page the form appears on. You can see this thread for an example:

    http://forum.gravityhelp.com/topic/correct-syntax-to-populate-fields-dynamically

    Or you would have to change your mini-form to use GET instead of POST and pass the values to the form via the query string.

    Either way you have to set the fields you want to populate dynamically as being able to be populated dynamically by editing those fields in the form builder, going to the advanced tab and turning on dynamic data population. You will then have to give the fields a parameter name. If you are passing data to them via the querystring this is the name you would use to pass the data to them (ex. firstname=XXXX&lastname=XXXX you would have to give those fields the parameter values of firstname and lastname).

    Posted 9 years ago on Tuesday March 16, 2010 | Permalink
  3. Thanks, I've got it working now. Cheers!

    Posted 9 years ago on Tuesday March 16, 2010 | Permalink