I need to conditionally set the #required property of a specific form field to FALSE. I know already that the requirement check is performed in _form_validate(). However this function is executed BEFORE any other custom attached validation handlers as it is in fact responsible for calling them.

So I'd like to know if there's a way to alter $form of $form_state BEFORE _form_validate() is called...?

Or maybe there are ways to perform the requirement check at a later time in validation?


PS: One could also do reverse thinking (make the field optional and require it in a custom validation handler), but there are reasons I cannot do this.

  • you can use hook_form_alter() to alter required property of field based on conditions. – ARUN Dec 18 '13 at 15:29
  • The property needs to be changed on submit but before validation. hook_form_alter() alters the form array at build time. – Propaganistas Dec 19 '13 at 8:13
  • whats the issue you are facing when you change the requrired property at build time? – ARUN Dec 19 '13 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.