1

In my drupal6 site I have wizard form. I implemented it with FormAPI using form storage and the rebuild property. My form validation is being done with the #required property and with functions in the #element_validate property. It's working fine but for one thing, when I click on the previous button the form is being validated and I don't want it to. Is there a smart and right way to disable the validations when a specific button of the form is clicked?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Luiz Guilherme
  • 1,601
  • 21
  • 37

3 Answers3

1

Kevin's answer works. You could also try http://drupal.org/project/skip_validation where you would add an additional property to your previous button,'#skip_validation' => TRUE

aterchin
  • 39
  • 4
1

The only way to do this cleanly (unfortunately) is to avoid the use of #required = TRUE and validate it yourself in a validation handler, taking into account knowledge of what 'step' the form is on in the wizard process.

One common approach is to accumulate all of your in-progress data in $form_state['storage'], where it will persist between rebuilds.

Eaton
  • 7,405
  • 2
  • 26
  • 24
  • Thanks. I'm using the $form_state['storage']. Unfortunately I'll have to do what you said and implement a required validation function and then verify there if the user has clicked on the previous button and do not validate. – Luiz Guilherme Feb 21 '09 at 12:11
1
  // hack to clear validation errors during wizard processing
  form_set_error(NULL, FALSE, TRUE);
  unset($_SESSION['messages']['error']);