Created
July 14, 2010 20:13
-
-
Save cirpo/475994 to your computer and use it in GitHub Desktop.
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
| <?php | |
| class AttachementNameAndAttachmentFileValidatorSchema extends sfValidatorSchema | |
| { | |
| protected function configure($options = array(), $messages = array()) | |
| { | |
| $this->addMessage('attachment_name', 'Il nome dell\'allegato è obbligatorio.'); | |
| $this->addMessage('attachment_file', 'Caricare un file.'); | |
| } | |
| protected function doClean($values) | |
| { | |
| $errorSchema = new sfValidatorErrorSchema($this); | |
| // attachment_file is filled but no attachment_name | |
| if ($values['attachment_file'] && !$values['attachment_name']) | |
| { | |
| $errorSchema->addError(new sfValidatorError($this, 'required'), 'attachment_name'); | |
| } | |
| // attachment_name is filled but no attachment_file | |
| if (!$values['attachment_file'] && $values['attachment_name']) | |
| { | |
| $errorSchema->addError(new sfValidatorError($this, 'required'), 'attachment_file'); | |
| } | |
| // no attachment_file and no attachment_name, remove the empty values | |
| if (!$values['attachment_file'] && !$values['attachment_name']) | |
| { | |
| unset($values['attachment_file']); | |
| unset($values['attachment_name']); | |
| } | |
| // throws the error for the main form | |
| if (count($errorSchema)) | |
| { | |
| throw new sfValidatorErrorSchema($this, $errorSchema); | |
| } | |
| return $values; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment