have a question about form validate. I write a form called formA and a function called formA_validate.
In the function I validate the input of the formA, if there are something wrong it will call the function drupal_set_error() and set a error message. But if I submit the form to another page, the error message disappeared.
If I could prevent submit when validate the form input?
I would appreciate it if someone can help me.

[Heine - removed <h3>]

Comments

mooffie’s picture

if I submit the form to another page

How exactly do you submit the form to this other page?

Are you doing $form['#action'] = 'the/other/page'? If 'the/other/page' doesn't contain the form then no validation/submit phase will take place (and thus no messeges will be generated).

Please explain what you're trying to do and maybe we could figure some other way to achieve it.

john.yi’s picture

Thank you for your reply.
I set the $form['#action'] = 'the/other/page'. And want to validate the form in the current page.
I think I have a wrong understanding of the validate.
If I want to validate the form , should I write validate function in the page which the form posted to?

mooffie’s picture

It's the drupal_get_form() call that triggers the validation. Some options:

1. display the form on 'some/other/page' too; or:
2. remove the $form['#action'] and instead do the redirection in the submit handler (which happens after validation).