How to omit form's validation at AJAX button click? I have an AJAX button that should update form fields according to data already provided by user:

 'ajax_button' =&gt; array(
    '#type' =&gt; 'button',
    '#value' =&gt; t("Scan for tags"),
    '#ajax' =&gt; array(
      'callback' =&gt; 'ajax_tag',
      'wrapper' =&gt; 'dynamic-tags-fieldset',
      'method' =&gt; 'replace',
      'event' =&gt; 'click',
      'prevent' =&gt; 'submit click mousedown',
    ),
  ),


It works, but only if form is valid. Of course I do not want to validate it just yet. I don't care if all fields are filled, I only need my form to be updated at this very moment. How can I make form api not to invoke hook_form_validate() and not test #required fields?
You can use the #limit_validation_errors property:


  Provides an array of sections which are parts of $form_state['values'] which should be validated, implying that sections which are not listed should not be validated. This is normally used in multistep forms in the case of a "back" button, for example, where '#limit_validation_errors' => array() would mean not to validate anything as form values on the current page are to be discarded anyway. #limit_validation_errors does not have any effect if #submit is not set. More discussion is in the form_set_error() documentation.


e.g.

'ajax_button' =&gt; array(
    '#type' =&gt; 'button',
    '#value' =&gt; t("Scan for tags"),
    '#ajax' =&gt; array(
      'callback' =&gt; 'ajax_tag',
      'wrapper' =&gt; 'dynamic-tags-fieldset',
      'method' =&gt; 'replace',
      'event' =&gt; 'click',
      'prevent' =&gt; 'submit click mousedown',
    ),
    '#limit_validation_errors' =&gt; array(), // No elements will be validated
    '#submit' =&gt; array('custom_function'), // An explicit submit functions array is required for this, but may be empty
  ),


However, each validation function is free to respect '#limit_validation_errors' or not. If you want your validation functions to respect this parameter, you need to:


Obtain #limit_validation_errors value from clicked button using $form_state['clicked_button']['#limit_validation_errors']
Pass it as a third argument to each form_set_error() call