/**
  * Rewrite bind event to overload
  * @param array $data
  * @param $entity
  * @param null $whitelist
  */
 public function bind(array $data, $entity, $whitelist = null)
 {
     //Validator for email address format
     if (!empty($data['email'])) {
         $this->get('email')->addValidator(new EmailValidator(['message' => '<strong>Email</strong> address is invalid.']));
         $this->get('email')->addValidator(new Uniqueness(['collection' => 'User', 'field' => 'email', 'message' => '<strong>Email</strong> is already used by another account.']));
     }
     parent::bind($data, $entity, $whitelist);
 }
Exemple #2
0
 private function processForm($params, BaseForm $form)
 {
     $form->bind($params);
     if ($form->isValid()) {
         $form->save();
         return true;
     }
     return false;
 }
 /**
  * Binds the form with input values, adding recaptcha values
  * @param array $taintedValues  An array of input values
  * @param array $taintedFiles   An array of uploaded files (in the $_FILES or $_GET format)
  */
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     if (sfConfig::get('app_recaptcha_active', false)) {
         $request = sfContext::getInstance()->getRequest();
         $taintedValues['challenge'] = $request->getParameter('recaptcha_challenge_field');
         $taintedValues['response'] = $request->getParameter('recaptcha_response_field');
     }
     parent::bind($taintedValues, $taintedFiles);
 }
Exemple #4
0
 protected function processForm(sfWebRequest $request, BaseForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $schedule = $form->save();
         $this->getUser()->setFlash('notice', $form->isNew() ? 'The schedule has added' : 'The schedule has updated');
         $results = explode('-', $schedule->start_date);
         $this->redirect(sprintf('@calendar_year_month?year=%d&month=%d', $results[0], $results[1]));
     }
 }
Exemple #5
0
 public function bind(array $data, $entity, $whitelist = null)
 {
     if (!isset($data['status'])) {
         $data['status'] = 0;
     }
     //Validator for date and time
     if ($data['type'] == 'once') {
         $this->get('datetime')->addValidator(new DateTimeValidator());
     }
     //validator for job_sel
     if ($data['type'] == 'repetitiv') {
         $this->get('job_sel')->addValidator(new PresenceOf(['message' => 'Choose a period to setup a cron.']));
     }
     //Validator for cron custom definition
     if ($data['job_sel'] == 'custom') {
         $this->get('job')->addValidator(new PresenceOf(array('message' => 'The cron custom def. is required.')));
     }
     parent::bind($data, $entity, $whitelist);
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     if (isset($taintedValues['newVal'])) {
         foreach ($taintedValues['newVal'] as $key => $newVal) {
             if (!isset($this['newVal'][$key])) {
                 $taintedValues['newVal'][$key]['referenced_relation'] = $this->options['table'];
                 $taintedValues['newVal'][$key]['record_id'] = $this->options['id'];
                 $this->addValue($key);
             }
         }
     }
     if (isset($taintedValues['VernacularNames'])) {
         foreach ($taintedValues['VernacularNames'] as $key => $newVal) {
             $taintedValues['VernacularNames'][$key]['referenced_relation'] = $this->options['table'];
             $taintedValues['VernacularNames'][$key]['record_id'] = $this->options['id'];
         }
     }
     parent::bind($taintedValues, $taintedFiles);
 }
 public function checkCSRFProtection()
 {
     $form = new BaseForm();
     $form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
     if (!$form->isValid()) {
         throw $form->getErrorSchema();
     }
 }
 public function executeDeletePair(sfWebRequest $request)
 {
     $pair = MappingPairTable::getInstance()->find($request->getParameter('id'));
     if (!$pair) {
         return $this->notFound();
     }
     /* @var $pair MappingPair */
     $form = new BaseForm();
     $form->getWidgetSchema()->setNameFormat('delete_pair[%s]');
     $form->bind($request->getPostParameter($form->getName()));
     if ($form->isValid()) {
         $id = $pair->getId();
         $pair->delete();
         return $this->ajax()->remove('#pair_' . $id)->remove('#pair_form_' . $id)->render();
     } else {
         return $this->ajax()->form($form)->render();
     }
 }
        $this->setWidget('body', new sfWidgetFormTextarea());
        $this->setValidator('body', new sfValidatorString(array('min_length' => 12)));
    }
}
$configuration = $configuration->getApplicationConfiguration('frontend', 'test', true, null, $configuration->getEventDispatcher());
sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));
$enhancer = new sfFormYamlEnhancerTest($configuration->getConfigCache());
// ->enhance()
$t->diag('->enhance()');
$form = new CommentForm();
$form->bind(array('body' => '+1'));
$enhancer->enhance($form);
$t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances labels');
$t->like($form['body']->render(), '/class="comment"/', '->enhance() enhances widgets');
$t->like($form['body']->renderError(), '/You haven\'t written enough/', '->enhance() enhances error messages');
$form = new CommentForm();
$form->bind();
$enhancer->enhance($form);
$t->like($form['body']->renderError(), '/A base required message/', '->enhance() considers inheritance');
class SpecialCommentForm extends CommentForm
{
}
$form = new SpecialCommentForm();
$form->bind();
$enhancer->enhance($form);
$t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() applies parent config');
$form = new BaseForm();
$form->embedForm('comment', new CommentForm());
$form->bind();
$enhancer->enhance($form);
$t->like($form['comment']['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances embedded forms');
Exemple #10
0
 private function processForm(BaseForm $form, sfWebRequest $request, $type = null)
 {
     $name = $form->getName();
     $form->bind($request->getParameter($name), $request->getFiles($name));
     if ($this->setFlashMessageByType($form->isValid(), $type)) {
         $form->save();
     }
     $this->redirect('@opCalendarPlugin');
 }