当前位置: 首页>>代码示例>>PHP>>正文


PHP FormBuilderInterface::addValidator方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::addValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::addValidator方法的具体用法?PHP FormBuilderInterface::addValidator怎么用?PHP FormBuilderInterface::addValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormBuilderInterface的用法示例。


在下文中一共展示了FormBuilderInterface::addValidator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
     $years = range(date('y'), date('y') + 4);
     $builder->add('card_brand', 'choice', array('choices' => array_combine($this->brands, $this->brands), 'required' => true))->add('card_number', 'text', array('required' => true))->add('card_name', 'text', array('required' => true))->add('card_cvv', 'number', array('required' => true))->add('date_month', 'choice', array('choices' => array_combine($months, $months), 'required' => true))->add('date_year', 'choice', array('choices' => array_combine($years, $years), 'required' => true));
     $translator = $this->translator;
     $transactionManager = $this->transactionManager;
     $builder->addValidator(new CallbackValidator(function (FormInterface $form) use($translator, $transactionManager) {
         if ($form->get('date_year')->getData() . $form->get('date_month')->getData() < date('ym')) {
             $form->get('date_month')->addError(new FormError($translator->trans("alias.date_expired", array(), 'ogone')));
             return;
         }
         if (mb_strlen($form->get('card_cvv')->getData()) != 3) {
             $form->get('card_cvv')->addError(new FormError($translator->trans("card_cvv.invalid", array(), 'ogone')));
             return;
         }
         // Check card using ogone
         try {
             $transactionManager->checkAuthorisation(0, $form->get('card_brand')->getData(), $form->get('card_number')->getData(), $form->get('date_month')->getData() . $form->get('date_year')->getData(), $form->get('card_name')->getData(), $form->get('card_cvv')->getData(), null);
         } catch (\Pilot\OgonePaymentBundle\Exception\InvalidBatchDatasException $e) {
             foreach ($e->getErrors() as $error) {
                 $code = $error->xpath('NCERROR');
                 $code = (string) $code[0];
                 $field = $form;
                 $message = $translator->trans('error.' . $code, array(), 'ogone');
                 if ($message == 'error.' . $code) {
                     // Not yet translated
                     $ogoneMessage = $error->xpath('ERROR');
                     $ogoneMessage = (string) $ogoneMessage[0];
                     $message = sprintf('[%s] %s', $code, $ogoneMessage);
                 }
                 if ($code == 50001002) {
                     $field = $form->get('card_number');
                 }
                 $field->addError(new FormError($message));
             }
         }
     }));
 }
开发者ID:sasedev,项目名称:samenjoy,代码行数:39,代码来源:AliasType.php

示例2: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->key = $builder->getForm()->getName();
     $builder->addValidator(new CaptchaValidator($this->session, $this->key, $options['invalid_message'], $options['bypass_code']));
 }
开发者ID:rjmunro,项目名称:CaptchaBundle,代码行数:5,代码来源:CaptchaType.php

示例3: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $options = $this->getDefaultOptions();
     $builder->addValidator($this->validator)->setAttribute('option_validator', $options['validator'])->setAttribute('configs', $options['configs']);
 }
开发者ID:r4cker,项目名称:GenemuFormBundle,代码行数:8,代码来源:ReCaptchaType.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->captcha->setOptions($options);
     $builder->addValidator(new CaptchaValidator($this->captcha))->setAttribute('captcha', $this->captcha)->setAttribute('format', $options['format'])->setAttribute('position', $options['position']);
 }
开发者ID:rafalzmuda,项目名称:GenemuFormBundle,代码行数:8,代码来源:CaptchaType.php

示例5: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addValidator($this->validator)->setAttribute('option_validator', $options['validator']);
 }
开发者ID:hykz,项目名称:Depot,代码行数:7,代码来源:ReCaptchaType.php


注:本文中的Symfony\Component\Form\FormBuilderInterface::addValidator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。