1

I have a content type having 10 fields that are all required. How do I skip validation for some fields? Is there any hook/function that allow me to do this?

  • Do you want that to decide after submission or before submission? – Shubham Dec 21 '15 at 11:51
  • After save button clicked. – Rajesh Vishwakarma Dec 21 '15 at 12:27
  • you can edit the required field and change it's setting. – WaQaR Ali Dec 21 '15 at 13:07
  • @WaQaR Ali fields are depend on other value, so I cant not change this form settings. – Rajesh Vishwakarma Dec 21 '15 at 13:12
  • then you should follow the hook_form_alter as written in below answer. – WaQaR Ali Dec 21 '15 at 13:23
1

I consider that by

How do I skip validation

you mean "make the fields not compulsory" (UI level)

If that is the case then you can use hook_form_alter and change the ['#required'] setting, for any form element, to FALSE.

Keep in mind that hook_form_alter is a generic hook invoked by any form in your site (performance issue) alternative you may use hook_form_FORM_ID_alter to "to talk" to a specific form. Hope that helps.

If you want to make the validation on a different level, you have to write your own validation handlers (['#validate']) or override Drupal's, like node_form_validate

1

For deciding and skipping some fields after submit follow the following steps.

Step 1: Perform HOOK_form_alter and add a custom function in $form['#validate] array, remember your custom validate function must add on 0th key of the array.

Step 2: Perform your calculation and find on which fields you want to perform the validations, and set them in $form['#limit_validation_errors'].

I hope this will help you for the skipping validation.

  • I have to skip some required fields value based on other required value. This will checked run time once user clicked on save button. – Rajesh Vishwakarma Dec 23 '15 at 8:25

Your Answer

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

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