Pre_render and auto populate

This is probably easy for someone who has the coding experience, but I am working with Gravity PDF and I need two fields (one text field and one date field) to auto populate the current user logged in and today’s date, but it needs to be part of the pre_render filter.

I was able to get the name using gform_field_value_dr_name, but can’t seem to get that to work within gform_pre_render.

Any help would be great. Thanks!

Hello. Why is it imperative to use gform_pre_render, rather than using gform_field_value?

These fields are being populated as part of the edit entry screen of a gravity view. Apparently gform_field_value doesn’t run during edit entry while gform_pre_render does. Thanks!

The user editing the form would be a different user than the user who initially submitted the form.

Does that make sense?

add_filter( 'gform_pre_render_1', 'populate_checkbox', 5002 );
add_filter( 'gform_pre_validation_1', 'populate_checkbox', 5002);
add_filter( 'gform_pre_submission_filter_1', 'populate_checkbox', 5002);
add_filter( 'gform_admin_pre_render_1', 'populate_checkbox', 5002);
function populate_checkbox( $form ) {
 $fields = $form['fields'];
    foreach( $form['fields'] as &$field ) {
  if($field->id == 127){
        $choices = $field->choices;
        foreach($choices as &$choice){ 
                   if($choice['value'] == 'In writing'){
                             $choice['isSelected'] = true;
                   }
        }
  }
	
  if($field->id == 174){
	  	$new_user = wp_get_current_user();
# Get the user's first and last name
$first_name = $new_user->first_name;
$last_name = $new_user->last_name;
	$full_name = $first_name . ' ' . $last_name;
		$field->defaultValue = $full_name;
   }
  }
    
    return $form;
}

This code seems to put the user name in as the default value, but the checkbox doesn’t stay selected. Any idea what I am missing? Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.