Created
January 29, 2011 06:26
-
-
Save jmather/801602 to your computer and use it in GitHub Desktop.
How you can post validate embedded forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestForm | |
{ | |
public function configure() | |
{ | |
// ... snip ... | |
$eForm = new SomeObjectEmbeddedForm($this->getObject()->SomeObject); | |
$this->embedForm('some_object', $eForm); | |
$this->validatorSchema->setPostValidator( | |
new sfValidatorCallback(array('callback' => array($this, 'contextualChecks'))) | |
); | |
} | |
public function contextualChecks($validator, $values) | |
{ | |
if ($values['some_object']['some_checkbox'] == 1 && $values['some_object']['some_field'] == '') | |
{ | |
$error = new sfValidatorError($validator, 'Field is required when Checkbox 1 is checked.'); | |
$ves = new sfValidatorErrorSchema($validator, array('some_field' => $error)); | |
throw $ves; | |
} | |
return $values; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment