Skip to content

Instantly share code, notes, and snippets.

@jmather
Created January 29, 2011 06:26
Show Gist options
  • Save jmather/801602 to your computer and use it in GitHub Desktop.
Save jmather/801602 to your computer and use it in GitHub Desktop.
How you can post validate embedded forms
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