$this->addElement('text', 'projected-start', array(
'required' => false,
'validators' => array (
array('date', false, array('MM/dd/yyyy'))
),
'label' => 'Projected Start:',
'class' => 'form-date'
));
I'm extending Zend_Form to create a new custom fo开发者_运维知识库rm. I tried to validate a date using the code above but it simply is not working and nothing is displaying when I enter an invalid input. Any help on this one?
EDIT:
class Application_Form_CreateProject extends Zend_Form
{
public function init()
{ ... }
}
Thats the start of extending the form.
$form = new Application_Form_CreateProject();
$request = $this->getRequest();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
echo "true";
}
}
$this->view->form = $form;
That's the controller
echo $this->form->setAction($this->url());
That's the view
What do you get when you try this:
$f = new Zend_Form();
$f->addElement('text', 'projected-start', array(
'required' => false,
'validators' => array (
array('date', false, array('MM/dd/yyyy'))
),
'label' => 'Projected Start:',
'class' => 'form-date'
));
$data = array(
'projected-start' => '13/03/2011'
);
var_dump( $f->isValid( $data ) );
var_dump( $f->getErrors() );
die;
You could try this
$this->addElement('text', 'projected-start', array(
'required' => false,
'validators' => array (
new Zend_Validate_Date(array('format' => 'MM/dd/yyyy'))
),
'label' => 'Projected Start:',
'class' => 'form-date'
));
精彩评论