PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm » Bug #3150

Incorrect check for 'select' elements in RuleRegistry::_getJsValue()

Details

Submitted2005-01-10 13:29 UTC
Fromsebab at info dot com dot pl
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP VersionIrrelevant
OSirrelevant
Roadmaps(Not assigned)

Comments

[2005-01-10 13:29 UTC] sebab at info dot com dot pl

Description:
------------
Required rule for Hierselect doesn't work - form is being submitted with empty values set in hs element.
It's probably caused by bug in RuleRegistry.php _getJsValue() method (line 236 in latest version $Id: RuleRegistry.php,v 1.12 2004/02/28 15:47:22 avb Exp $) where JS "case" statement checks if element is 'select' type, where JS element property for <select> tag receives one of the following values:
select-multiple - The MULTIPLE attribute is true. Multiple OPTION elements can be selected.
select-one - Default. The MULTIPLE attribute is false. Only one OPTION element can be selected. (according to MSDN DHTML library http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/type_9.asp)

HTML_QuickForm 3.2.4pl1

Reproduce code:
---------------
modified code from pear docs for QF (elements.php)
<?php
require_once 'HTML/QuickForm.php';
$form =& new HTML_QuickForm('frmTest', 'get');
$renderer =& $form->defaultRenderer();

$form->addElement('submit', 'isubTest', 'Test Submit');

$main[''] = "";
$main[1] = "Pop";
$main[2] = "Rock";

$secondary[1][0] = "Belle & Sebastian";
$secondary[1][1] = "Elliot Smith";
$secondary[2][3] = "Noir Desir";
$secondary[2][4] = "Violent Femmes";
$opts[] = $main;
$opts[] = $secondary;
$hs =& $form->addElement('hierselect', 'ihsTest', 'Hierarchical select:', array('style' => 'width: 20em;'), '<br />');
$hs->setOptions($opts);
$form->addRule('ihsTest', 'HS is a required field', 'required', null, 'client');

if ($form->validate()) {
$form->freeze();
echo '<pre>';
var_dump($form->exportValues());
echo '</pre>';
}
$form->display();
?>

Expected result:
----------------
if submit with empty values for hs element alert with error msg should be displayed.

Actual result:
--------------
form submits with empty values for hs element.

[2005-01-13 15:45 UTC] sebab at info dot com dot pl

Indeed that works. Thanks. But, correct me if I'm wrong, shouldn't SWITCH in JavaScript validate_frmTest() catch on 'select' instead on 'default' as it does now? For hierselect element of course. If you add
alert(_element.name+":"+_element.type);
somewhere inside the SWITCH you'll see that type is never 'select' but 'select-one' or 'select-multiple'.