Details
Description
bug:
$form->addElement("text", "abc"); $form->abc->setLabel("please enter a zero")->setRequired(true);
this will be impossible
bug2:
$form->addElement("text", "abc"); $form->abc->setLabel("enter a number (1 to 100)")->addValidator("between", false, array(1, 100));
user enters a 0 and it's ok!
note: I typed the above bugs right here, so there might be some things spelled wrong etc...
fix:
Index: Form/Element.php
===================================================================
--- Form/Element.php (revision 8741)
+++ Form/Element.php (working copy)
@@ -1146,7 +1147,7 @@
$this->setValue($value);
$value = $this->getValue();
- if (empty($value) && !$this->isRequired() && $this->getAllowEmpty()) {
+ if ($value === "" && !$this->isRequired() && $this->getAllowEmpty()) {
return true;
}
Index: Validate/NotEmpty.php
===================================================================
--- Validate/NotEmpty.php (revision 8741)
+++ Validate/NotEmpty.php (working copy)
@@ -59,7 +59,7 @@
$this->_setValue($valueString);
- if (empty($value)) {
+ if ($value === "") {
$this->_error();
return false;
}
// edit, new:
Index: Form/Element.php
===================================================================
--- Form/Element.php (revision 8819)
+++ Form/Element.php (working copy)
@@ -407,7 +407,7 @@
public function setName($name)
{
$name = $this->filtername($name);
- if (('0' !== $name) && empty($name)) {
+ if ($name === '') {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty');
}
Issue Links
| This issue is duplicated by: | ||||
| ZF-3236 | CLONE -value "0" is treated as empty |
|
|
|
Also option in Zend_Form_Element_Multiselect with key "0" can not be marked as 'selected' via ->populate() or ->setValue(). For example: http://www.nabble.com/Zend_Form_Element_Multiselect-and-option-with-key-'0'-td15853694s16154.html