Edit report at https://pear.php.net/bugs/bug.php?id=20071&edit=1
ID: 20071
Updated by: loki_angel@mail.ru
Reported By: loki_angel at mail dot ru
Summary: Validation problem with default value
Status: Bogus
Type: Bug
Package: HTML_QuickForm2
Package Version: 2.0.0
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
But input field could be completely deleted through Firebug for example.
In this case
not valid form validates as valid. Also data could be sended by script -
not by browser.
Previous Comments:
------------------------------------------------------------------------
[2013-09-22 14:07:20] avb
-Status: Open
+Status: Bogus
null value can't appear in $_POST unless you put it there manually. If
you run the code with 'first' => '', which is the actual submit value
for empty field, validation will run as expected.
------------------------------------------------------------------------
[2013-09-22 12:43:42] loki
Description:
------------
Fields with default values has a problem with validation
Test script:
---------------
$form = new HTML_QuickForm2(null, 'post');
$first=$form->addElement('text', 'first', array('value'=>111));
$second=$form->addElement('text', 'second');
$first->addRule(
'callback',
'Error in field 1',
array('callback'=>'checkField1',
'arguments'=>array(false))
);
$second->addRule(
'required',
'Error in field 2'
);
function checkField1($value) {
return 111==$value;
}
if ($form->validate()) {
echo 'valid';
} else {
echo 'not valid';
}
//recived post data
$_POST=array( 'first'=>222, 'second'=>'some value' ); //not valid
$_POST=array( 'first'=>null, 'second'=>'some value' ); //valid
$_POST=array( 'second'=>'some value' ); //valid
------------------------------------------------------------------------