Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created June 21, 2019 22:25
Show Gist options
  • Save leepettijohn/b06c224da5d844a0f83420f6ce4298a3 to your computer and use it in GitHub Desktop.
Save leepettijohn/b06c224da5d844a0f83420f6ce4298a3 to your computer and use it in GitHub Desktop.
Gravity Forms - Populate the Name Field from a GET variable which is the user ID
add_filter( 'gform_pre_render_6', 'populate_user_info' );
add_filter( 'gform_pre_validation_6', 'populate_user_info' );
add_filter( 'gform_pre_submission_filter_6', 'populate_user_info' );
add_filter( 'gform_admin_pre_render_6', 'populate_user_info' );
function populate_user_info( $form ) {
$userid = sanitize_text_field($_GET['userid']);
foreach ( $form['fields'] as &$field ) {
if ($field->type == 'name'){
$field->inputs[1]['defaultValue'] = get_first_name($userid);
$field->inputs[3]['defaultValue'] = get_last_name($userid);
}
}
return $form;
}
function get_first_name($userid){
$userinfo = get_userdata($userid);
return $userinfo->first_name;
}
function get_last_name($userid){
$userinfo = get_userdata($userid);
return $userinfo->last_name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment