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.

Merge Tag as a default value for Admin Only field?

  1. I am experiencing problems getting a default value to show up using merge tags. I'm trying to make the default value a combination of two form field values entered earlier in the form.

    Example:
    First Name: John
    Last Name: Smith
    Title (admin labeled "post_title"): Vice President
    Post Title (hidden field only visible to admin): John Smith - Vice President (that's the desired output I'm looking for.)

    Here is the merge tag combo I'm using in the default value:
    {Name (First):6.3} {Name (Last):6.6} - {post_title:8}

    It only spits back out the merge tag code as the form value though, no the actual entries from the form fields I want combined. (I.E. "Post Title: {Name (First):6.3} {Name (Last):6.6} - {post_title:8}")

    Note: I've also tried {Name (First):6.3:value} {Name (Last):6.6:value} - {post_title:8:value} with the same results.

    I've reviewed http://www.gravityhelp.com/documentation/page/Merge_Tags and feel like maybe I'm getting field names and field labels mixed up, but I also went to the notifications tab and output the merge tags for the fields I'm targeting and used those exactly with the same results.

    Posted 11 years ago on Thursday March 28, 2013 | Permalink
  2. The merge tags are parsed when the form is rendered. However, those form values have not yet been entered. How would that field be populated with a default value for a field which does not yet have any data entered in it?

    If you want to copy data from one field to another after it is entered in your form (from an earlier field in the form to a later field) you can use jQuery, like this: http://www.gravityhelp.com/forums/topic/passing-values-on-multipage-form#post-179789

    Posted 11 years ago on Sunday March 31, 2013 | Permalink
  3. I'll try the jQuery solution, thank you. I'm not trying to populate the value before the form is submitted however, I just want the merge tag combo to show up in submitted results. (The data should be there for them to display after the submit button is pressed, right?)

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  4. David Peralty

    You could then also use one of our pre-submission hooks to copy the values from the other fields on submit, merge them the way you want, and stuff them into another field. gform_pre_submission

    http://www.gravityhelp.com/documentation/page/Gform_pre_submission

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  5. Thanks, Chris & David! This gives me some good options to find the solution I need.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  6. David, I am trying the hooks method and it seems to work, only not with merge tags. I tried generating regular text and that worked, so I tried a custom merge tag from my form, and that only spit back out the merge tag code. So I tried a standard merge tag and that also just generated the code verbatim in my results rather than the value for that field like I want.

    Here is what I am trying:

    add_action("gform_pre_submission_2", "pre_submission_handler");
    function pre_submission_handler($form){
        $_POST["input_3"] = "{date_mdy}";
    }

    And the results are simply the merge tag "{date_mdy}" rather than the value I want to show up (in this case, the date). Is there a filter I need to use to tell the function to recognize those characters as a merge tag instead of plain text?

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  7. David Peralty

    You can't use merge tags in PHP. You'll have to pull field values and then push field values. Have a look at the details here as well to help: http://www.gravityhelp.com/documentation/page/Gform_validation

    So you'll want something like:
    $_POST["input_3"] = $_POST["input_4"] ." ". $_POST["input_5"] ." - ". $_POST["input_6"];
    To get your First Name Last Name - Title that you wanted in your original post.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  8. So close, that got me 50% there! My last hurdle is the name field. I used the advanced field "Name" (format: normal). And I can't get the value to output. I've tried:

    $_POST["input_1"]

    and

    $_POST["input_1.1"] ." ". $_POST["input_1.2"]

    and

    $_POST["input_1.3"] ." ". $_POST["input_1.6"]
    (this is the designation for the first/last name fields in the merge tag from the notification section)

    Is there a different designation for the multi-field advanced fields?

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  9. David Peralty

    View source the form HTML and check what designation it is given there, as it might be different from them merge tags.

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  10. It was input_1.3 & input_1.6 so I guess:

    $_POST["input_1.3"] ." ". $_POST["input_1.6"]

    should be working. Alas, it is not.

    EDIT: Found the solution: I used "input_1_3" instead of input_1.3 and it worked.

    Consider this issue solved. Thank you for all your help!

    Posted 11 years ago on Monday April 1, 2013 | Permalink
  11. David Peralty

    Try changing the dot to an underscore.
    input_1_3 and input_1_6

    Posted 11 years ago on Monday April 1, 2013 | Permalink

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