Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.16

Bug #5644 Client javascript validation of single radio box fails
Submitted: 2005-10-10 13:07 UTC
From: martin at bymartin dot com Assigned: avb
Status: Closed Package: HTML_QuickForm
PHP Version: Irrelevant OS: freeBSD
Roadmaps: (Not assigned)    
Subscription  


 [2005-10-10 13:07 UTC] martin at bymartin dot com
Description: ------------ When you have a radio box with only one radio option the client javascript validation always reports that the item is not selected. If you disable client validation in the "required" form rule the form validates OK. Or if you add a second radio box (with the same name) the client javascript validated the form correctly to. Test script: --------------- <?php // Load the main class require_once 'HTML/QuickForm.php'; // Instantiate the HTML_QuickForm object $form = new HTML_QuickForm('firstForm'); // Set defaults for the form elements $form->setDefaults(array( 'name' => 'Joe User' )); // Add some elements to the form $form->addElement('header', null, 'QuickForm tutorial example'); $form->addElement('text', 'name', 'Enter your name:', array('size' => 50, 'maxlength' => 255)); $form->addElement('radio','Radio','Radio: ','first and only radio box','test'); //$form->addElement('radio','Radio','Radio: ','second radio box','test2'); $form->addElement('submit', null, 'Send'); // Define filters and validation rules $form->applyFilter('name', 'trim'); $form->addRule('name', 'Please enter your name', 'required', null, 'client'); $form->addRule('Radio', 'Please check radio box', 'required', null, 'client'); // Try to validate a form if ($form->validate()) { echo '<h1>Hello, ' . htmlspecialchars($form->exportValue('name')) . '!</h1>'; exit; } // Output the form $form->display(); ?> Expected result: ---------------- When you select Radio the form should validate OK. Actual result: -------------- The form always failes.

Comments

 [2005-11-01 11:30 UTC] avb
The javascript code expects to find an array in form.elements['Radio'] while in reality there is just a form element. This behaviour should be fixed. Adding a single radio button to the form is bad from usability perspective, though. You should consider using a checkbox instead.
 [2006-06-18 17:06 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.