FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=16443&edit=1

ID: 16443
Updated by: borz_off@cs.msu.su
Reported By: andrewj at alanblunden dot co dot uk
Summary: HTML_quickform $form->validate() returns true on
pearError
-Status: Open
+Status: Bogus
Type: Feature/Change Request
-Package: HTML_QuickForm2
+Package: HTML_QuickForm
Operating System: Windows Server 2003
Package Version: Unknown
PHP Version: 5.2.5
Roadmap Versions:
New Comment:

-Status: Open
+Status: Bogus
-Package: HTML_QuickForm2
+Package: HTML_QuickForm
PEAR_Error is an object and thus evaluates to true in accordance to PHP
rules:
http://www.php.net/manual/en/language.types.boolean.php

You should explicitly test for PEAR_Error or set an error handler which
will make it harder to miss the errors.

Wrong package, also.


Previous Comments:
------------------------------------------------------------------------

[2009-07-16 17:19:17] #81568bed335c1fb270f

Description:
------------
Form validates as true not matter what if the user codes a validation
function and doesn't code it properly or if the users custom validation
function doesn't return a value.

Test script:
---------------
<?PHP

//required includes/loaders
require_once 'D:\codebase\codebase_config.php';

//set the security on this page
main::setSecurity('1|2|3|4|5|6|7|8|9|10');

require_once 'HTML/QuickForm.php';

//instantiate a new HTML_quickform object to use with the form
include(s) below
$form = new HTML_QuickForm('form', 'post',
$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);

//add storage question
$form->addElement('select', 'storage_type', 'Please tell us where the
Caravan is kept',
array(
'CASSOA' => 'CaSSoA Site',
'Home' => 'At Home, on a driveway',
'WFARM' => 'On a Working Farm',
'NWFARM' => 'On a Non-Working Farm',
'Other' => 'Other'
),
array(
'id' => 'storage_type'
)
);

//add address fields
$form->addElement('text', 'storage_address_1', 'Storage Address (Line
1)',
array(
'onfocus' => 'lightrow(this)',
'onblur' => 'lightrow(this)',
'id' => 'storage_address_1'
)
);

$form->addElement('text', 'storage_address_2', 'Storage Address (Line
2)',
array(
'onfocus' => 'lightrow(this)',
'onblur' => 'lightrow(this)',
'id' => 'storage_address_2'
)
);

$form->addElement('text', 'storage_address_3', 'Town',
array(
'onfocus' => 'lightrow(this)',
'onblur' => 'lightrow(this)',
'id' => 'storage_address_3'
)
);

$form->addElement('text', 'storage_address_4', 'County',
array(
'onfocus' => 'lightrow(this)',
'onblur' => 'lightrow(this)',
'id' => 'storage_address_4'
)
);

$form->addElement('text', 'storage_postcode', 'Postcode',
array(
'onfocus' => 'lightrow(this)',
'onblur' => 'lightrow(this)',
'id' => 'storage_postcode'
)
);

//add validation rule
function checkCassoa($fields) {
$errors[] = array();
$flag = 0;
if($fields['storage_type'] == 'CASSOA') {
if($fields['storage_address_1'] == '') {
$errors['storage_address_1'] = 'Required Field';
$flag=1;
}
if($fields['storage_address_3'] == '') {
$errors['storage_address_3'] = 'Required Field';
$flag=1;
}
if($fields['storage_postcode'] == '') {
$errors['storage_postcode'] = 'Required Field';
$flag=1;
}
return ($flag==0) ? true : $errors; //ERROR IN USER CODE - THIS LINE
SHOULD BE AFTER THE IF BLOCK
}
//NOTHING BEING RETURNED HERE DUE TO ABOVE ERROR
}

$form->addFormRule('checkCassoa');

$form->addElement('submit', 'submit', 'Continue',
array('id'=>'submit','class'=>'button'));

if($form->validate()) {
//BECUASE $form->validate() IS OUTPUTTING PearErrors, form validates
to true and ignores all validation rules
//THIS IS A PROBLEM AS USER DOESNT KNOW THEY CREATED AN ERROR AND THE
FORM VALIDATES NO MATTER WHAT
var_dump($form->validate());
die();
}

//display the form render to the screen
$form->display();
?>

Expected result:
----------------
Form does not validate, ie $form->validate() == false or PearError

Actual result:
--------------
$form->validate() == true;

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJul 17, '09 at 7:49p
activeJul 17, '09 at 7:49p
posts1
users1
websitepear.php.net

1 user in discussion

Borz_off: 1 post

People

Translate

site design / logo © 2021 Grokbase