Using hook_form_alter I have tried to add limit validation errors to workflow submission button.

In form alter I'm getting two form_id's one is normal node add form_id and another is workflow state form_id.

$form['actions']['workflow_course_status_save_as_draft']['#limit_validation_errors'] > = array(array('field_sample_course'));
  • Some validations cannot be skipped. What are your variation errors? – Eyal Mar 9 '17 at 18:59
  • Fields are getting skipped if I add limit validation errors to submit button. But not working with workflow action buttons. – Sri Harsha Mar 10 '17 at 7:17
  • Could you post complete code sample and screenshot of var_dump($form_id) ? – Oleg Videnov Mar 13 '17 at 2:18

I did exactly the same but we were wrong in the usage of #limit_validation_errors.

The reason why this is failing is that we're not using properly #limit_validation_errors. This issue has nothing to do with Workflow.

During the form validation, if this property is set (validation errors are limited), Drupal core will remove any non validated form values from the form state, so only values that passed validation will be left for submit callbacks.

For Drupal 8: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Form/FormValidator.php#n147

For Drupal 7: http://cgit.drupalcode.org/drupal/tree/includes/form.inc?h=7.x#n1193

My solution was to add a custom validation that will be executed at end of all validations, and in there remove all form-related errors:

 * Removes all validation errors that could happen when saving a draft
 * @param $form
 * @param $form_state
function my_custom_draft_validation($form, &$form_state) {
  $errors = form_get_errors();

  if (!empty($errors)) {
    $messages = drupal_get_messages('error', TRUE);

    // Remove error messages originated during the form validation
    foreach ($messages['error'] as $error) {
      if (!in_array($error, $errors)) {
        drupal_set_message('error', $error);

    // Remove all form errors

If #limit_validation_errors is set on a clicked button, the button must also define a #submit property (may be set to an empty array).

Please refer the link https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormState.php/function/FormState%3A%3AsetErrorByName/8.2.x

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.