我正在使用 Float 验证来验证 Zend_Form 字段上的数据。
但是验证的行为是值得关注的。
如果表单是通过 Firefox 或 Chrome 发布的,它会正确验证,但在通过 IE 使用时会显示无效。
使用 IE,它验证任何大于 10 的值,即大于 10.00,但如果该值小于 10.00,则表示无效
没有为表单定义语言环境,所以我猜它会默认为en
.
我知道验证是在服务器端起作用的东西,客户端界面不应该产生影响,但它似乎仍然如此。
表格类:
class Application_Form_Custom extends Zend_Form {
public function init() {
$this->setMethod('post');
$this->setName('form_custom');
$this->setElementFilters(array('StringTrim','StripTags'));
$notEmpty = new Zend_Validate_NotEmpty();
$notEmpty->setMessage('Value is required', 'isEmpty');
$valid_float = new Zend_Validate_Float();
$valid_float -> setMessages(array(
'floatInvalid' => 'Invalid',
'notFloat' => 'Invalid'
));
$deposit = new Zend_Form_Element_Text(array(
'name' => 'txtDeposit',
'style' => 'width:99%;',
'autocomplete' => 'off'
));
$deposit -> setLabel('Deposit : ');
$deposit -> setValue('0.00');
$deposit -> setRequired(true);
$deposit -> addValidators(array(array(
$notEmpty,
true
), array(
$valid_float,
true
)));
$submit = new Zend_Form_Element_Submit('btnSubmit');
$submit -> setLabel('Submit');
$reset = new Zend_Form_Element_Reset('btnReset');
$reset -> setLabel('Reset');
$this->addElements(array(
$deposit,
$submit,
$reset
));
}
}
控制器:
class FormsController extends Zend_Controller_Action {
public function customFormAction() {
$form= new Application_Form_Custom();
if ($this->getRequest()->isPost() && $form->isValid($this->_request->getPost())) {
///...blah...blah...about my process
}
$this->view->form =$form;
}
}
看法 :
<form id="<?php echo $this->form->getName(); ?>" name="<?php echo $this->form->getName(); ?>" action="" method="<?php echo $this->form->getMethod(); ?>">
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr>
<td align="left" valign="top" nowrap="nowrap">Deposit</td>
<td><?php echo $this->form->txtDeposit->renderViewHelper();
if(count($this->form->txtDeposit->getMessages()) > 0) {
?><br />
<div style="color:#F00;">
<?php
$i=0;
foreach($this->form->txtDeposit->getMessages() as $msg) {
echo $msg;
$i++;
if(count($this->form->txtDeposit->getMessages())>$i) {
echo '<br />';
}
}
?>
</div>
<?php
}
?></td>
</tr>
<tr align="left" valign="top">
<td colspan="2" align="center" nowrap="nowrap"><?php echo $this->form->btnSubmit->renderViewHelper(); ?> <?php echo $this->form->btnReset->renderViewHelper(); ?></td>
</tr>
</table>
</form>