symfony validation problem
im testing symfony form validation.
the problem is very simple.
no matter what i put in the body text area and post it, i keep getting "Required" back.
i dont know why.
i just have one validation rule.
here is the code: code
what is wrong/how can i debug?
thanks
UPDATE: it has something to do with the binding in the controller.
cause even if i delete the validation the form will still not be valid and it will be passed to the template but this time without the "Required".
so it wont be valid no matter if ive got the validation or not.
it has something to do with the embedForm() maybe? someone that has validated an embeded form?
i have printed the error messages out with
<?
foreach ($form->getErrorSchema() as $field => $error) {
printf("%s: %s\n", $field, $error->getMessage());
echo "<br />";
}
?>
and i get:
0: Unexpected extra form field开发者_StackOverflow中文版 named "body".
thread: body [Required.]
_csrf_token: Required.
Body
do they mean that thread:body is required or csrf is required?
thanks
First of all, try echoing the form without being specific, eg:
<?php echo $form; ?>
If this works, then it's something to do with your form echoing code. I'd suggest checking the HTML source of that page then, to see what the default form code renders, and comparing that with what your code outputs above. If the names of the fields are different, therein lies your answer - it could be a form name format as Radu suggests.
On a separate note, don't forget to use:
<?php echo $form->renderHiddenFields(); ?>
as well in your template, so that the CSRF token field gets rendered. This will remove your "_csrf_token: Required" form error.
Have you checked what parameters are sent through POST?
Maybe adding the following in your form setup method will help:
$this->widgetSchema->setNameFormat('thread[%s]');
精彩评论