Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Gravity Forms: pre-populate data WordPress

  • SOLVED

Hi Experts,

Quick overview:

- I have a contact form on my website powered by GravityForms plugin
- The form is only presented to logged-in users
- all is working well


Help request:

- I would like to add an "Email" field to the form which automatically pulls in the user's email address.
- The email address should be already filled in when user visits the form for the first time.
- I've attached a screenshot of the desired final-result


Thanks for your expert help!

Cheers :)

Answers (1)

2015-05-07

Kyle answers:

This should work

add_filter("gform_pre_render_8", "populate_email"); // change to your form ID
function populate_email( $form ){


foreach( $form["fields"] as &$field ){

if( $field["id"] == 5 ){ //change to your field ID

$user = wp_get_current_user();
$field["defaultValue"] = $user->user_email;

}

}

return $form;

}


Kyle comments:

Actually, I just checked and if you go to an email form field. Then hit the appearance tab. Then the placeholder option. On the right side you can select "user email".


WP Answers comments:

Hey Kyle,

Thanks for your help. I also just realized the same thing! user_email is already a built-in option. :-/

Hey if you don't mind I will keep this question open as I continue to finalize my Contact Form today. It's likely I may run into other similar issue which perhaps you can help me with?

If it turns out that I need no help by the end of the day I will simply award you the prize money for your time.

Sound ok?


Kyle comments:

Sounds good