Home » HTML » HTML_QuickForm » Bug #7120
javascript error when using >1 addrule(type=numeric)
Details
| Submitted | 2006-03-14 19:00 UTC |
|---|---|
| From | alansaviolobo at yahoo dot co dot in |
| Status | Wont fix |
| Package | HTML_QuickForm |
| PHP Version | 5.0.4 |
| OS | windows xp |
| Roadmaps | (Not assigned) |
Comments
[2006-03-14 19:00 UTC] alansaviolobo at yahoo dot co dot in
Description:
------------
I created a form with 2 textboxes and set 2 rules each on them. one rule was the "required" rule while the other rule specified the data type expected. one was set to numeric while the other was set to alphanumeric.
all the rules were set to CLIENT SIDE PROCESSING.
the problem that occured was that the javascript generated was declaring the variable "regex" everytime the "datatype" rule was set. this resulted in firefox not processing the script. and thus the javascript failed.
also the variable _qfMsg is not declared but directly used.
the script given below fails at the second textbox. i cant explain that behaviour.
Test script:
---------------
<?php
require_once "HTML/QuickForm.php";
$form = new HTML_QuickForm('frmTest', 'post');
$form->addElement('text','ltag','LTAG');
$form->addElement('text','length','LENGTH');
$form->addElement('reset', 'btnClear','Clear');
$form->addElement('submit', 'btnSubmit', 'Submit');
$temp=array("ltag","length");
$form->addRule('ltag', 'Please enter the ltag', 'required',null,'client');
$form->addRule('ltag', 'Please enter alphanumeric', 'alphanumeric');
$form->addRule('length', 'Please enter the length', 'required');
$form->addRule('length', 'Please enter numeric', 'numeric',null,'client');
$form->applyFilter('ltag', 'trim');
$form->applyFilter('length', 'trim');
if ($form->validate()) {
# If the form validates, freeze and process the data
$form->freeze();
$form->process("process_data", false);
}
else
{
$form->display();
}
function process_data ($values)
{
foreach ($values as $key=>$value)
echo $key."=".$value."<br>";
}
?>
Expected result:
----------------
the type validation for the second field should succeed when a value of say 45 or 34.45 is entered.
Actual result:
--------------
the above case fails. the javascript popup box says: please enter numeric.
[2006-03-14 20:19 UTC] alansaviolobo at yahoo dot co dot in
modifications made to various files
-----------------------------------
line 1751 of quickform.php
=> introduced var in line "qfMsg = ''"
line 1752 of quickform.php
=> introduced on line "var regex;"
line 85 of quickform/rule/regex.php => removed "var" from string.
now, in the generated javascript,
this works : frm.elements['ltag'].value (correct value)
this does not work : frm.elements['length'].value (undefined)
html file:-
<form action="/pear error check test.php" method="post" name="frmTest" id="frmTest" onsubmit="try { var myValidator = validate_frmTest; } catch(e) { return true; } return myValidator(this);">
<input name="ltag" type="text">
<input name="length" type="text">
<input name="btnClear" value="Clear" type="reset">
<input name="btnSubmit" value="Submit" type="submit">
</form>