通过 Zend_Form 和 Zend_Validate_Date 验证日期的输入字段
$this->addElement('text', 'projected-start', array(
'required' => false,
'validators' => array (
array('date', false, array('MM/dd/yyyy'))
),
'label' => 'Projected Start:',
'class' => 'form-date'
));
我正在扩展 Zend_Form 以创建新的自定义表单。我尝试使用上面的代码验证日期,但它根本不起作用,当我输入无效的输入时,什么也没有显示。对这个有什么帮助吗?
编辑:
class Application_Form_CreateProject extends Zend_Form
{
public function init()
{ ... }
}
这是扩展表单的开始。
$form = new Application_Form_CreateProject();
$request = $this->getRequest();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
echo "true";
}
}
$this->view->form = $form;
这就是控制器
echo $this->form->setAction($this->url());
这就是视图
$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 form. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当你尝试这个时你会得到什么:
What do you get when you try this:
你可以试试这个
You could try this