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.

Dynamically populate field within template file

  1. I want to populate a form field with current post custom field that contains email address. I want to do it via template when embedding a form. Form is always the same, just this field needs to be populated in order to send enquiry directly to that email.

    I'm using this chunk of code:

    $owneremail = '\'owneremail\'=>\''.$o_email.'\'';
    echo gravity_form(1, false, false, array($owneremail), '', false);

    echoing $owneremail gives 'owneremail'=>'example@example.com' which should be fine according to your docs.
    Form has a field that has checkbox ticked to populate dynamically with value owneremail.

    And it doesn't get filled out.
    You can see the form here: http://holidaysincroatia.hr/summer/accommodation/apartmani-nije-mi-dobro/#cnt-form
    WP 3.5.1
    GF 1.6.11

    Posted 11 years ago on Monday February 18, 2013 | Permalink
  2. I suspect it has something to do with the $owneremail not truly being an array, but trying to look like one. I'm not sure what's wring with your array of parameter values exactly, but maybe you can approach is another way:

    [php]
    echo do_shortcode("[gravityform id=\"1\" title=\"false\" description=\"false\" field_values=\"owneremail=$o_email\"]");
    Posted 11 years ago on Monday February 18, 2013 | Permalink
  3. Funny, actually pretty strange that it does work with do_shortcode :confused:

    You made a small mistake with variable, it should be like this, then it works:
    echo do_shortcode('[gravityform id=\'1\' title=\'false\' description=\'false\' field_values=\'owneremail='.$o_email.'\']');

    Thanks for helping out.

    Posted 11 years ago on Monday February 18, 2013 | Permalink
  4. Glad you worked it out. Sorry about the typo.. I think it is related to the format of the array you were trying to fake in the first example. So we worked around it by using the do_shortcode and a different format for the parameters.

    Posted 11 years ago on Monday February 18, 2013 | Permalink

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