我已经为电话号码定义了一个字段集。这包含字段“类型”(私人、Office 移动...)和“号码”。数字的输入过滤器是“required => true”:
``
class PhoneFieldset extends BaseFieldset implements InputFilterProviderInterface
{
public function __construct()
{
parent::__construct('phones');
$this->setHydrator(new DoctrineHydrator($this->getEntityManager(), 'HtsBase\Entity\Phone'))
->setObject(new Phone());
$this->add(array(
'type' => 'DoctrineORMModule\Form\Element\EntitySelect',
'name' => 'type',
'options' => array(
'label' => 'Type',
'empty_option' => '',
'object_manager' => $this->getEntityManager(),
'target_class' => 'HtsBase\Entity\OptionlistPhoneType',
'property' => 'name',
),
'attributes' => array(
#'id' => 'type',
'class' => 'input-medium',
),
));
$this->add(array(
'name' => 'number',
'options' => array(
'label' => 'Number',
),
'attributes' => array(
'type' => 'text',
#'id' => 'number',
'class' => 'input-medium',
'maxlength' => '25',
'autocomplete' => 'off',
),
));
}
public function getInputFilterSpecification()
{
return array(
'type' => array(
'required' => false,
),
'number' => array(
'required' => true,
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'max' => 25,
),
),
),
),
);
}
``
我可以将验证器/过滤器附加到整个字段集吗?因此,如果“类型”和“数字”为空,则字段集有效,但验证是否至少填写了一个?