Skip to content

Instantly share code, notes, and snippets.

@cirpo
Created July 14, 2010 20:13
Show Gist options
  • Select an option

  • Save cirpo/475994 to your computer and use it in GitHub Desktop.

Select an option

Save cirpo/475994 to your computer and use it in GitHub Desktop.
<?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