Does any one knows if it is possible to change the '#required' in a custom validate handler?

I have tried the following:

function mymodule_validate_handler($form, &$form_state){
 if($ignore) {
   foreach fieldset($form) as f do
     foreach fiedlset_elements(f) as fe do
         $form[f][fe]['#required'] = false;
 }
}

Well, this does not works. I still get the message:
XXXX field is required

any idea?

Comments

gpk’s picture

Try getting rid of the #required property via hook_form_alter().

maozet’s picture

Well, i haven't described the full story...
I am working on a multipage registration form, those splitting up all the fields into couple of steps(do that in form_alter).
Sopuse i currently on page 2 which has a required field and i hit the Back button.
I take care of the step in myform_submit_handler but i can't get rid of the error messaged. In my form_validate_handler I have tried to unset the elements or set #required to false, but none of those do the job.

I could set all fields to #required=false on creation of each page and to check them all at validate_handler but Is there a Drupal way to do it

regards,

jaypan’s picture

First off, if you are creating a multipage registration, you should do this using hook_user, unless you are only splitting up username and password (the two preexisting fields).
Second, the back button doesn't work properly on any mutli-step forms.
Third, you can do what you want using hook_form_alter(), but it won't work when you use the back button, since the back button doesn't work properly with mutli-step forms.

Contact me to contract me for D7 -> D10/11 migrations.

maozet’s picture

What do you mean doesnt work properly?

jaypan’s picture

The opposite of working properly :D

I.e. it has unexpected results. For example, if you have a four page form, and click back on page four, it will take you back to page two, and you lose and/or save some of the values.

Contact me to contract me for D7 -> D10/11 migrations.

maozet’s picture

Are you talking about multistep module???
Incase you do, then I am not using it or any other module.

jaypan’s picture

No, I'm talking about using the form api when creating modules.

Contact me to contract me for D7 -> D10/11 migrations.