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.

Use $_SESSION variable to populate notification email field

  1. I have a $_SESSION variable set call $_SESSION['gwf_email'] Basically what I want to do is use the value stored within this variable to populate the "Send To Email" field on a form. Is this possible?

    Posted 8 years ago on Tuesday February 7, 2012 | Permalink
  2. Hi, imagebox,

    Yes, you can do this. In the admin, you need to go to the Advanced tab for your field and check "Allow field to be populated dynamically" and then give the field a unique name. You can then use the "gform_field_value_$parameter_name" hook (http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name) to populate the field with your session variable.

    Let me know if you have questions.

    Posted 8 years ago on Monday February 13, 2012 | Permalink
  3. I think I may not have been clear. What I am trying to do is populate the field value of the field in the admin panel in which you type in the email address of the person you wish to have form entries emailed to.

    If I a hidden field on the form which is capturing and storing the value of $_SESSION['gwf_email'] , How do I feed that value to the field which decides who should receive the new form submission ?

    Posted 8 years ago on Monday February 13, 2012 | Permalink
  4. Ah, for that we have two hooks, one for the Notification to User and one for the Notification to Administrator. Both of these hooks will allow you to use a value from the posted form. Take a look at these and let me know if you have questions.

    For the user notification email, there is the "gform_autoresponder_email" hook (http://www.gravityhelp.com/documentation/page/Gform_autoresponder_email).

    For the admin notification email, there is the "gform_notification_email" (http://www.gravityhelp.com/documentation/page/Gform_notification_email)

    Posted 8 years ago on Monday February 13, 2012 | Permalink
  5. Also the hidden field is not populating the value.

    This is the HTML code being rendered within the form on the page (http://globalwealthfactor.com/test-form/)

    <li id="field_1_8" class="gfield gform_hidden">
    <input id="input_1_8" class="gform_hidden" type="hidden" value="" name="input_8">
    </li>

    This is what I have in my functions file:

    add_filter("gform_field_value_email", "sponsor_email");
    function sponsor_email($value){
    	return $_SESSION['gwf_email'];
    }

    You can see a screen shot of the field properties at : http://globalwealthfactor.com/wp-content/themes/stealth-child/images/gf-scrn-shot.jpg

    Thank you :-)

    Posted 8 years ago on Tuesday February 14, 2012 | Permalink
  6. Make sure you use the parameter name you setup in the admin when calling the hook. So, since the parameter name is "sponsor_email", your code should be:

    add_filter("gform_field_value_sponsor_email", "sponsor_email");
    function sponsor_email($value){
    	return $_SESSION['gwf_email'];
    }
    Posted 8 years ago on Tuesday February 14, 2012 | Permalink

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