Home » HTML » HTML_QuickForm » Bug #5644
Client javascript validation of single radio box fails
Details
| 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) |
Comments
[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.