2

I have a form witch contains embededForms.

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']
5
  • groups.google.com/group/symfony-devs/browse_thread/thread/… Commented Jun 16, 2011 at 8:06
  • 1
    Uwe: that link is about Symfony2, which is an entirely different subject. Commented Jun 16, 2011 at 8:25
  • Where is the postvalidator set? In the embedded form or in the container form? Commented Jun 16, 2011 at 8:27
  • in the containerform. I need a value from the containerform to validate the embedded form. Commented Jun 16, 2011 at 14:49
  • Hi all pls help me with this question stackoverflow.com/questions/16498386/… Thanks you Commented May 13, 2013 at 15:18

2 Answers 2

1

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));
Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately, post validators in embedded form's aren't run when the container form is validated.
That's not true, they are copied while embedding to the container form, as is the entire validatorschema.
0
$error = new sfValidatorError($validator, 'invalid');
$errorschema = new sfValidatorErrorSchema($validator, array('field' => $error));
throw new sfValidatorErrorSchema($validator, array('embeddedformname' => $errorschema));

this worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.