本文整理汇总了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));
}
}
}));
}
示例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']));
}
示例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']);
}
示例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']);
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addValidator($this->validator)->setAttribute('option_validator', $options['validator']);
}