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

Request #7432 Client side validation
Submitted: 2006-04-20 08:27 UTC
From: gdalle at cg06 dot fr Assigned: avb
Status: Closed Package: HTML_QuickForm2 (version 3.2.5)
PHP Version: 4.3.10 OS: Win Xp
Roadmaps: 0.5.0    
Subscription  


 [2006-04-20 08:27 UTC] gdalle at cg06 dot fr (Gilles)
Description: ------------ I've added a rule to an hidden element of the form. The rule calls a JavaScript function who check the validation. When the value of the element is empty, the JS validation function isn't called. Is there a way to force the calling of this function ? I can modify the JavaScript generated code by updating the Callback.php file (QuickForm/Rule) but it's not "clean". Is there an another way ? Test script: --------------- Here is my code : $oSelect =& $oQuickForm->addElement("hidden","ID_CATEGORIE_LIST",""); $oQuickForm->registerRule("checkCategorie","callback","checkCategorie"); $oQuickForm->addRule("ID_CATEGORIE_LIST","bla bla bla","checkCategorie",null,"client"); Here is the JavaScript generated code : value = frm.elements['ID_CATEGORIE_LIST'].value; if (value != '' && !checkCategorie(value) && !errFlag['ID_CATEGORIE_LIST']) { errFlag['ID_CATEGORIE_LIST'] = true; _qfMsg = _qfMsg + '\n bla bla bla'; } Expected result: ---------------- The JS validation function should be executed. Actual result: -------------- The JavaScript validation function isn't executed because the generated code don't call the JavaScript validation function if the value of the element is empty.

Comments

 [2006-04-21 10:09 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-04-21 11:08 UTC] gdalle at cg06 dot fr
OK, but how to check an element whatever its value? In my exemple, the element is required sometimes according to an other element value. Thus, I can't set this element to required with a rule like : $oQuickForm->addRule("ID_CATEGORIE_LIST","bla bla bla","required","","client"); The JS checking function must be called all the time.
 [2006-04-26 11:53 UTC] ankur at motreja dot com (Ankur Motreja)
Hi, I'm facing the same problem and I agree with Gilles - if the programmer defines a custom client-side validation function, HTML QuickForm should just pass on the job of checking to it. Changing the following line of code in HTML/QuickForm/Rule/Callback.php (near the end of the file) return array('', "{jsVar} != '' && !{$callback}({$params})"); to the following fixes the issue return array('', "!{$callback}({$params})"); If you'd like to see an example of the problem where one element might depend on the value of another element, please see the code at http://www.motreja.com/ankur/plain_quickform.txt Here, textbox 1 is required only if choice 1 is selected, textbox 2 is required only if choice 2 is selected, etc. To test, you need to select one of the choices and leave all other text fields blank. If you haven't made the code change mentioned above, submit is successful. Otherwise, it will bring up an alert box saying you need to fill up the correct textbox. If the programmer defines additional rules like required for an element that has a custom validation rule, another javascript if block is generated for that. Therefore, this change will affect only the callback rule (am I right?). So, this change will always call the callback without additional checks.
 [2006-06-03 14:40 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-06-18 20:14 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-07-20 14:28 UTC] areddan at silverarm dot ie (Alan Reddan)
Description -------------- What happens is the button onclick overrides the onSubmit and passes the validation to displayWaiting() This performs the validation routine by directly calling the quickFrom client side javascript, if this is ok then it moves onto the next step which is to display a progress bar animated gif called loading.gif using setTimeout as a form submit cocks up animation and IE. This works with IE 6.0 and Mozilla 1.5 Solution --------------------------- ########Your php script $form =& new HTML_QuickForm('bookme', 'post'); $form->addElement('checkbox', 'checked_terms', array('Terms & Conditions', ''.$click),'',array('class' =>'bkChe')); $form->addRule('checked_terms', 'You must indicate you have read our terms and conditions', 'required', null, 'client'); $submit_data_tr =<<$submit_data
</td></tr> EOF; $form->addElement('html',$submit_data_tr); $buttons[] = &HTML_QuickForm::createElement('button', '', $finish,array('class' =>'qfSub','onclick' =>'displayWaiting();')); $form->display();
 [2010-10-07 19:26 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!