I am using Symfony 2.
The way my forms are working is like the following :
Forms are submitted in Ajax (JQuery)
If there are errors in my form, I receive an XML response with all error messages
<errors>
<error id="name">This field cannot be blank</error>
<error id="email">This email address is not valid</error>
<error id="birthday">Birthday cannot be in the future</error>
</errors>
- If there is no error in my form, I receive an XML response with redirect URL
<redirect url="/confirm"></redirect>
- My question is : how can I change "forever" the behavior of forms in Symfony 2 so that I could use a controller like the following :
public function registerAction(Request $request)
{
$member = new Member();
$form = $this->createFormBuilder($member)
->add('name', 'text')
->add('email', 'email')
->add('birthday', 'date')
->getForm();
if($request->getMethod() == 'POST') {
$form->bindRequest($request);
if($form->isValid()) {
// returns XML response with redirect URL
}
else {
// returns XML response with error messages
}
}
// returns HTML form
}
Thanks for your help,
Regards,