0

I am working on the node edit form, and I want to remove all field validation when users click on Save as unpublished.

Is it possible?

I didn't write any code right now, so I don't have any code to show.

1
  • Yes, it's possible, this module does the same based on user roles [Bypass Form Validations] (drupal.org/project/bypass_form_validations). take look how they do that. take look at the module to see how they implement that and it could be a good start to write your code.
    – Ziftman
    Nov 11, 2017 at 10:55

1 Answer 1

1

You could do this approach in HOOK_form_alter. Depending on validation that you want to remove... I provide you a simple example of required fields: Suppose you have an Image field that it's required, you could make it unrequired using the following:

$form['field_image']['widget']['0']['#required'] =  TRUE;

Also if you want to remove the "Alt field" for a image you could use:

$form['field_image']['widget']['0']['#alt_field'] =  FALSE;
1
  • 1
    You are altering the field configuration and not how validation works
    – wranvaud
    Jul 19, 2019 at 14:58

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.