Multipages form, variables are empty in the backend

I have a problem, the following code does not work.
Either the variables are empty or it displays values from the last recorded entry.
This is a multipage form.

add_filter( 'gform_form_post_get_meta', 'update_form_field_values' );
 
function update_form_field_values( $form ) {

if ( $form['id'] != 1 ) {
    return $form;
}

$value_to_check = rgar( $form, '6' );
$value_of_field_ip = rgar( $form, '7.3' );
$value_of_field_in = rgar( $form, '7.6' );

if ( $value_to_check == 'Mineur' ) {
  $value_of_field_rp = rgar( $form, '21.3' );
  $value_of_field_rn = rgar( $form, '21.6' );
}

foreach ( $form['fields'] as &$field ) {
  if ( $field->id == 62 ) {
    if($value_to_check == 'Value1') {
      
      $field->label = "$value_of_field_rp $value_of_field_rn, of $value_of_field_ip $value_of_field_in :";
    } else {
      $field->label = " $value_of_field_ip $value_of_field_in :";
    }
  
  break;
  }

}

return $form;
}

My previous code who working for frontend user, but not saved in the backend :


add_filter( 'gform_pre_render', 'update_form_field_values', 10, 2 );

function update_form_field_values( $form, $is_ajax ) {
if ( $form['id'] != 1 ) {
return $form;
}

$entry = RGFormsModel::get_current_lead();
$value_to_check = rgar( $entry, '6' );
$value_of_field_ip = rgar( $entry, '7.3' );
$value_of_field_in = rgar( $entry, '7.6' );

if ( $value_to_check == 'Mineur' ) {
  $value_of_field_rp = rgar( $entry, '21.3' );
  $value_of_field_rn = rgar( $entry, '21.6' );
}


foreach ( $form['fields'] as &$field ) {
  if ( $field->id == 62 ) {
    if($value_to_check == 'Value1') {
      
      $field->label = "$value_of_field_rp $value_of_field_rn, of $value_of_field_ip $value_of_field_in :";
    } else {
      $field->label = "$value_of_field_ip $value_of_field_in :";
    }
  
  break;
  }

}


return $form;
}

The first code block utilizes the gform_form_post_get_meta filter, which runs after the form is loaded and modifies the label of field 62 based on the values of fields 6, 7, and 21. However, these changes will only be visible on the front end and not saved on the backend.

The second code block uses the gform_pre_render filter, which runs before the form is displayed to the user. This code retrieves the current entry and alters the label of field 62 based on the values of fields 6, 7, and 21. These changes will be reflected in both the front end and back end.

If the issue is that the values are empty or not up-to-date, it could be due to the way the entry is being retrieved using RGFormsModel::get_current_lead(). It is essential to ensure that the correct entry is being retrieved and that the values of the fields are accurate.

The value are retrieved, because in the frontend the values are displayed, but not in the backend… like the label is not saved with values

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