2

In Drupal 7, How can I change certain fields to not be required using the form api, depending on which button they click to submit? It seems the validation is occuring before the validate function. Where can I change this before it gets there?

1 Answer 1

5

I believe the form validate hook triggers after the default validation which would include checking required fields. It might be easier to not mark the fields required by default and check in your validate hook if they need to be required and then throw a form error if necessary.

3
  • This won't cause the "required field" markup to be rendered out, which can cause UX and A11Y problems.
    – mpdonadio
    Jun 2, 2016 at 0:32
  • You would have to use JavaScript to help with UX. It is also bad UX to mark fields required that may not be required based on the selection. I'm not sure there is any other way to dynamically change the required fields.
    – Lonita
    Jun 2, 2016 at 14:50
  • yes this is what i did
    – Diana
    Jun 2, 2016 at 17:16

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.