Setting a Zend_Form_Element_Text as not required?

749 Views Asked by At

I'm new to Zend Framework and I want to validate the user input of the optional form field $start_date with a regex. The Problem is that I'm not able to set this Zend_Form_Element_Text as not required, whereby I can't send all form values to the DB as long as there are no inputs for this date. I tried ->setAllowEmpty() and ->setRequired().

The PHP Code looks like:

$start_date = new Zend_Form_Element_Text('start_date');
$start_date->setLabel('start_date')
    ->addFilter('StripTags')
    ->addFilter('StringTrim');
$start_date->setDecorators(array(
    'ViewHelper',
    'Errors',
    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element'))
    ));
$start_date->addValidator('regex', false, array('/((\d{2})|(\d))\/((\d{2})|(\d))\/((\d{4})|(\d{2}))/'));
$start_date->setAttribs(array('class'=>'eingabe nospace', 'pattern'=>'((\d{2})|(\d))\/((\d{2})|(\d))\/((\d{4})|(\d{2}))', 'title'=>'Format: dd.mm.yyyy'));

Thanks!

0

There are 0 best solutions below