Я хочу удалить Обязательный и Проверка формы из ZendFrameWork 2

0

Как удалить обязательное поле и проверить форму из следующего кода.

<?php
namespace Application\Form;

use Zend\Form\Form;

/**
 * Class DomainForm
 * @package Application\Form
 */
class DomainForm extends Form
{
    /**
     * @param string $name
     * @param array $options
     */
    public function __construct($name = '', $options = array())
    {
        parent::__construct($name);
        $this->setAttribute('method', 'post');
        $this->setAttribute('class', 'bottom-margin');
        $this->setAttribute('id', 'validateForm');

        $this->add(array(
            'name' => 'fullname',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'url',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'id_provider',
            'type' => 'Zend\Form\Element\Select',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'empty_option' => '-',
                'value_options' => $options['provider']
            )
        ));

        $this->add(array(
            'name' => 'id_hosting',
            'type' => 'Zend\Form\Element\Select',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'empty_option' => '-',
                'value_options' => $options['hosting']
            )
        ));

        $this->add(array(
            'name' => 'id_server',
            'type' => 'Zend\Form\Element\Select',
            'attributes' => array(
                'class' => 'form-control',
            ),
            'options' => array(
                'empty_option' => '-',
                'value_options' => $options['server']
            )
        ));

        $this->add(array(
            'name' => 'host_ftp',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'user_ftp',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'pwd_ftp',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'port_ftp',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'type_ftp',
            'type' => 'Zend\Form\Element\Select',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'empty_option' => '-',
                'value_options' => $options['type_ftp']
            )
        ));

        $this->add(array(
            'name' => 'auth_code',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'expired',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control input-datepicker'
            )
        ));

        $this->add(array(
            'name' => 'info',
            'type' => 'Zend\Form\Element\Textarea',
            'attributes' => array(
                'class' => 'form-control'
            )
        ));

        $this->add(array(
            'name' => 'id_customers',
            'type' => 'Zend\Form\Element\Select',
            'attributes' => array(
                'class' => 'form-control'
            ),
            'options' => array(
                'empty_option' => '-',
                'value_options' => $options['customers']
            )
        ));

        $this->add(array(
            'name' => 'price',
            'type' => 'Zend\Form\Element\Text',
            'attributes' => array(
                'class' => 'form-control',
                'placeholder' => '9999,99'
            )
        ));

        //...
    }
}
  • 0
    Еще немного информации? Только одно обязательное поле? Любой код контроллера?
Теги:
validation
forms
zend-framework2

1 ответ

0

С помощью контроллера вы можете изменить фильтр, чтобы пустые значения для этого поля:

$form->getInputFilter()->get('YOUR_FIELD')->setAllowEmpty(true);

В любом случае, ваш вопрос недостаточно ясен

Ещё вопросы

Сообщество Overcoder
Наверх
Меню