We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Multiple forms on one page

How to add multiple forms on one page? This works, but all the forms validate at once. How to validate only one and not show errors in others?



931
Accepted
answer

Ok, at this moment I create hidden field in each form definition:

$this->addHidden('formType', $className);

In controller I check formType value from request:


> if ($this->request->getPost('formType') == 'Form1')
> {
>     if ($form1->isValid(null, true))
>     { }
> }

> if ($this->request->getPost('formType') == 'Form2')
> {
>     if ($form2->isValid(null, true))
>     { }
> }