2

I am using the formapi to create a form. On one of my fields I have an #ajax call. When the field is changed I call the function. I recreate the form and then replace the whole form on the page. This works fine.

When creating the form I have some logic that sets the form state to see if a field has a value. If it has a value then I show some more fields. If the value is not set then I don't show the fields. I am showing the fields by setting the #access on the field.

I need to add some validation on the form when the ajax call is triggered. I have tried adding the validation using form_set_error() in the function that creates the form and in the ajax callback but the error is not displayed on the screen.

Am I going about this the wrong way completely? How can I get the form error to display?

0

If the name of your form is modulename_admin_form() then you can add a function modulename_admin_form_validate(&$form, &$form_state).

In that validate function you can form_set_error() from in that validate function.

  • So when the form is submitted the validation kicks in as requested. However when I do the ajax callback the form does not update. – user13134 May 9 '13 at 11:46
  • What do you mean by 'does not update'? What specifically are you (or are you not) seeing? – Jaypan Sep 22 '16 at 3:00

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.