开发者

display a symfony post-validation error in an embeded Form

I have a form witch contains embeded开发者_如何学运维Forms.

the Post-Validator:

$this->validatorSchema->setPostValidator(
  new sfValidatorCallback(
    array('callback' => array($this, 'myPostValidator'))
  )
);

I throw an error in the myPostValidator method:

$error = new sfValidatorError($validator, 'invalid ' . $values['embededform1']['field']);
throw new sfValidatorErrorSchema($validator, array('field' => $error));

now I get an global error for the root-form.

I want to display the error next to the correct field.

$values['embededform1']['field']


My first suggestion would be to add the post validator in the embedded form. While embedding it will copy the validator to the container form, and your code for throwing the exception should work as expected.

Alternative you can try the following in the callback on your container form:

$error = new sfValidatorError($validator, 'invalid');
$errorschema = new sfValidatorErrorSchema($validator, array('field' => $error));
throw new sfValidatorErrorSchema($validator, array('embeddedformname' => $errorschema));


$error = new sfValidatorError($validator, 'invalid');
$errorschema = new sfValidatorErrorSchema($validator, array('field' => $error));
throw new sfValidatorErrorSchema($validator, array('embeddedformname' => $errorschema));

this worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜