Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Tweeted twitter.com/#!/StackDrupal/status/112281052436897795
deleted 4 characters in body
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

In Drupal 6, I have a custom form validation function, where I:

  • CopyI copy the value from field A to field B, if field B is empty.
  • Call form_set_error()I call form_set_error() when the value in field B exceeds x number ofcontains more than X characters.

Validation works fine, and the error is set. The problem is that the value in field B is not retained when the form is rebuilt: field B remains empty. I want to keep the value in field B after validation (when the error is set) to make it easy for users to edit it down to the right length.

My validation function looks like this:

function myform_validate($form, &$form_state) {
  if (empty($form_state['values']['field_b']['0']['value'])) {
        $form_state['values']['field_b']['0']['value'] = $form_state['values']['field_a']['0']['value']; 
      }
      if (strlen($form_state['values']['field_b']['0']['value']) > 260) {
        form_set_error('field_b', 'Text in field b is too long');
      }
    }
  }
}

Any suggestions on how to retain the value in field B when the form is rebuilt?

In Drupal 6, I have a custom form validation function, where I:

  • Copy the value from field A to field B, if field B is empty.
  • Call form_set_error() when the value in field B exceeds x number of characters.

Validation works fine, and the error is set. The problem is that the value in field B is not retained when the form is rebuilt: field B remains empty. I want to keep the value in field B after validation (when the error is set) to make it easy for users to edit it down to the right length.

My validation function looks like this:

function myform_validate($form, &$form_state) {
  if (empty($form_state['values']['field_b']['0']['value'])) {
        $form_state['values']['field_b']['0']['value'] = $form_state['values']['field_a']['0']['value']; 
      }
      if (strlen($form_state['values']['field_b']['0']['value']) > 260) {
        form_set_error('field_b', 'Text in field b is too long');
      }
    }
  }
}

Any suggestions on how to retain the value in field B when the form is rebuilt?

In Drupal 6, I have a custom form validation function, where:

  • I copy the value from field A to field B, if field B is empty.
  • I call form_set_error() when the field B contains more than X characters.

Validation works fine, and the error is set. The problem is that the value in field B is not retained when the form is rebuilt: field B remains empty. I want to keep the value in field B after validation (when the error is set) to make it easy for users to edit it down to the right length.

My validation function looks like this:

function myform_validate($form, &$form_state) {
  if (empty($form_state['values']['field_b']['0']['value'])) {
        $form_state['values']['field_b']['0']['value'] = $form_state['values']['field_a']['0']['value']; 
      }
      if (strlen($form_state['values']['field_b']['0']['value']) > 260) {
        form_set_error('field_b', 'Text in field b is too long');
      }
    }
  }
}

Any suggestions on how to retain the value in field B when the form is rebuilt?

edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Retain values during myform_validate() (Drupal 6)

Source Link
Loading