I have a Drupal 7 form which I’m allowing the user to submit via AJAX. If the user does not fill out required fields, or enters invalid information, I can return that and alert the user via the form_get_errors() function. The problem is that these values are still on the “display stack” (not the correct term, I’m sure) – when the user refreshes the page, or navigates to another one, these previous errors are displayed.
Is there a way to set these errors not to display once I’ve grabbed them with form_get_errors()?
EDIT: One option I have would be to remove all validation functions, then manually do validation in my ajax submit handler…but I feel like that defeats the purpose of this form API. I’d like to use everything built in, but I just want the error messages not to be displayed.
A quick glance at the
form_set_error()function (which is called byform_get_errors()) shows it’s using the Drupal 7 static cache pattern to hold the error messages. You should be able to clear that cache by calling the following in your AJAX validation function:If you’re using the AJAX provided by the form API (i.e. setting
#ajaxon your form element) you might want to look at#limit_validation_errors()to see if that can help you out as well.