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.

Modify incoming field data dynamically

  1. hegeman
    Member

    Hi,
    I am able to pass incoming data to a form field. I set it up so that a parameter in the url is passed to a hidden field.
    Is it possible to modify the parameter in the url before it is input in the hidden field.
    I would like to encrypt the url parameter so that it is not visible in the address bar and than decrypt it before it goes as a value into the hidden field.

    Is this possible in some way?

    Thank you

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  2. This would be possible but you would then have to use the PHP method for populating a field dynamically and you would have to know how to obfuscate a querystring value and then deobfuscarte it using PHP and then insert the value into the field using PHP and an API hook.

    The code to pre-populate a field looks like this. This example uses a field who's dynamic parameter has been set to "firstname":

    add_filter("gform_field_value_firstname", "populate_firstname");
    function populate_firstname(){
    $firstname_value = "Test";
    return $firstname_value;
    }

    So depending on the parameter you entered in the field editor you would swap out "firstname" with your parameter in the above code. You would have to add to this code to get the querystring and deobfuscate it and then set the value to the deobfuscated value of the data.

    So the above code requires customizations on your part, it doesn't do the deobfuscation part. It's just an example of how to pre-populate a field using PHP.

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  3. hegeman
    Member

    Ah, thanks for your quick response. Exactly what I was looking for.
    I'll give it a try....

    many greetings, Han

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  4. hegeman
    Member

    Hi Carl,
    I'm almost there, I got a test form up and running where the parameters are read from the url and the deobsfuscated code is inserted correctly in two hidden fields in the form.

    But that info in the hidden fields is no longer appearing in the email notification that is sent. Those fields stay blank, whereas before they worked fine. Is that information coming from a different route?

    Unfortunately I cannot send a url as the site is developed behind a firewall.
    Any ideas are appreciated. I'm a bit stuck a this last final tiny step.

    Thank you,

    Han

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  5. Nope, the information comes from the form itself. So if you are populating the fields dynamically correctly it should save the data in those hidden fields. When you say those fields worked fine before, are you referring to before you tried to obfuscate them?

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  6. hegeman
    Member

    yes they worked fine when I when I had set it up so that the gravity form got the parameter directly from the url.
    Without the intermediate steps of grabbing it, changing it and feeding it into the form.

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  7. hegeman
    Member

    Hi Carl,
    I'm still fiddling about. I have it partly working. Forget my question for now. There seems to be something else wrong. Some parameters are passed, others not.... I'll figure that out first.

    Thanx, Han

    Posted 14 years ago on Wednesday August 25, 2010 | Permalink
  8. mattswan
    Member

    Hi Carl,

    http://www.grandchifleyhotels.com.au/wedding-enquiry/?HotelID=GCA

    in above link you can see gravity form. I want to pass hotel name in hidden field for this form when form being submitted. is it possible to do that?

    If yes then how?

    Thanks in advance.

    Posted 13 years ago on Tuesday January 11, 2011 | Permalink
  9. @mattswan Yes, you can populate fields via query string. You need to configure your field so that it can be populated dynamically and then pass the data to it via the query string. See the forum post below, it outlines how to do this.

    http://forum.gravityhelp.com/topic/pass-custom-field-from-a-post-into-a-form-that-post-links-to#post-14327

    Posted 13 years ago on Tuesday January 11, 2011 | Permalink
  10. mattswan
    Member

    Hey Carl!

    Thanks for your quick reply, but the Hotel name which I want to pass is I am fetching from the query in php. so is it possible to pass php variable in hidden field?

    Thanks.

    Posted 13 years ago on Wednesday January 12, 2011 | Permalink
  11. Hi Matt,

    Sounds like you want to prepoluate the value of your hidden field using a value provided through PHP. Here's a quick example of how to do that (notes in the code):

    http://pastie.org/1453308

    Posted 13 years ago on Wednesday January 12, 2011 | Permalink
  12. mattswan
    Member

    Hi David!

    I am using below code which is working fine for one site, but I am using multi-site functionality and each site have different form id.

    in the below function I am specifying form id so it is not working for all the sites.
    if you do any amendments in that code then it would be good. I will try your code too.

    add_action("gform_pre_submission", "pre_submission_handler");
    function pre_submission_handler($form_meta){
    global $_POST;
    // form id 1 is our main contact form
    if($form_meta["id"] != '14'){
    return;
    }
    //query to get HotelName and Function Manager Email Address
    $query = 'SELECT h.HotelName, h.Suburb, hcw.ContactName, hcw.ContactEmail, hcw.ContactPhone, hcw.ContactFax FROM Hotel AS h LEFT JOIN HotelConfWed AS hcw ON h.ID=hcw.HotelID WHERE hcw.AreaID=1502 AND h.ID="'. $_SESSION["HotelID"].'"';

    $HDetail = query_chg($query);

    while ($det = mssql_fetch_array($HDetail)) {
    $_POST["input_9"] = $det['HotelName'];
    }
    }

    Thanks

    Posted 13 years ago on Thursday January 13, 2011 | Permalink