Skip to content

Instantly share code, notes, and snippets.

@eugenoprea
Created March 13, 2013 14:47
Show Gist options
  • Save eugenoprea/5152825 to your computer and use it in GitHub Desktop.
Save eugenoprea/5152825 to your computer and use it in GitHub Desktop.
Gravity Forms - Populate Name Field - Setting Field Default Value Directly - Part 2.
// Adds a filter to form id 7. Replace 7 with your actual form id
add_filter('gform_pre_render_7', 'eo_form_pre_render');
function eo_form_pre_render($form)
{
// if no user is logged-in, do nothing
if ( !is_user_logged_in() )
return $form;
foreach ($form['fields'] as &$field)
{
// replace 2 with the actual ID of your Name field
if ( 2 == $field['id'] )
{
eo_populate_name_field($field, array(
'first' => eo_get_usermeta('first_name'),
'last' => eo_get_usermeta('last_name'),
));
break;
}
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment