我有一个简单的zend框架2表单和输入过滤器。我试图弄清楚如何验证信用卡的到期年份和月份不会落入过去。你怎么能有一个验证规则需要两个字段来验证correclty?
输入过滤器:
<?php
namespace Account\Form;
use Zend\InputFilter\InputFilter;
use Zend\Validator\CreditCard;
use Zend\Validator\Date;
class SuspendedPaymentFilter extends InputFilter
{
public function __construct()
{
$this->add(array(
'name' => 'expiration_month',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'not_empty'),
array(
'name' => 'date',
'options' => array(
'locale' => 'en',
'format' => 'm',
),
),
),
));
$this->add(array(
'name' => 'expiration_year',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'not_empty'),
array(
'name' => 'date',
'options' => array(
'locale' => 'en',
'format' => 'Y',
),
),
),
));
}
}
形式:
<?php
namespace Account\Form;
use Zend\Form\Form;
use Tools\Data\DateTime;
class PaymentForm extends Form
{
public function __construct($name = null)
{
parent::__construct('Payment');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/form-data');
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'expiration_month',
'attributes' => array(
'required' => 'required',
'class' => 'form-control',
),
'options' => array(
'label' => 'Expiration Month',
'value_options' => array(
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December',
),
),
));
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'expiration_year',
'attributes' => array(
'required' => 'required',
'class' => 'form-control',
),
'options' => array(
'label' => 'Expiration Year',
'value_options' => DateTime::returnXYears(10),
),
));
}
}
答案 0 :(得分:-1)
$inputFilter->add($factory->createInput(array(
'name' => 'date_serv',
'validators' => array(
array(
'name' => 'NotEmpty',
'options' => array(
'messages' => array(
'isEmpty' => 'Debe ingresar fecha de creación',
),
),
),
array(
'name'=>'Date',
'break_chain_on_failure'=>true,
'options'=>array(
'format'=>'Y-m-d',
'messages'=>array(
'dateFalseFormat'=>'Formato fecha invalida, debe ser dd-mm-yyyy',
'dateInvalidDate'=>'Fecha ínvalida'
),
),
),
array(
'name' => 'Between',
'options' => array(
'min' => '1970-01-01',
'max' => date('Y-m-d'),
'messages' => array(
'notBetween' => 'La fecha de creación no puede ser mayor a la fecha actual',
),
),
),
),
)));