0

In Drupal 6.20 I'm building a function that creates a multi-page form (my_form_process). On one page the user can select from a list of previously created addresses, or create a new one. If the user wants to create a new one, I use javascript & CSS to hide the selections and unhide the address form (address, city state zip, etc). To make sure the user provides the required data, I have a validate function (my_form_process_validate) that I set the error if the fields are blank. The trouble is that when the pages fails the validation, the my_form_process redraws the form with the validation errors, but defaults back to the "select from a list of previously created addresses", and the "create new" form elements with the errors is still hidden.

How can I tell the my_form_process that builds the form, when the validation has failed show the "create new" div, and hide the "select old" div? I've tried setting a $form['storage'] variable but the my_form_process doesn't seem to see it.


Here is some more info:

I tried adding a $form_state['validation_status'] = 'error' in the validation routine but still found that value not in the $form_state array used in the form function when an error was found.

However, when there was no error, the value was available. (a clue)

So, just for kicks, I removed the "form_set_error" line from the validation routine and now the value is available.

So now, I have to set

$form_state['validation_error'] = '<ol>'; 
$form_state['validation_status'] = 'error'; 
$form_state['validation_error'] .= '<li>' . t('address cannot be blank') . '</li>';
$form_state['validation_error'] .= '</ol>'; 

Then in the form function I can test the $form_state['validation_error'] and if 'error' then use

drupal_set_message($form_state['validation_error'],$form_state['validation_status']);

To display the message and then set the display property of the div's appropriately.

Sure seems like a bug in the "form_set_error" process, but I'm a newbie in Drupal/PHP land so I'm not really sure what I'm doing.

1 Answer 1

0

You should be able to pass values through the $form_state variable back and forth between the form function, validation function, and submit handler functions. This might help (if you haven't looked at this already) http://drupal.org/node/144132#multistep

2
  • Thanks for the link Shane - it helped some. I think I figured it out by trying out some other options. I'll share them below.
    – MojoMark
    Jun 2, 2011 at 19:46
  • posted my approach as an edit in the message body to maintain the unanswered status.
    – MojoMark
    Jun 2, 2011 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.