quickform controller back button javascript issue

From: Date: Mon, 31 Oct 2005 15:56:55 +0000
Subject: quickform controller back button javascript issue
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21717@lists.php.net to get a copy of this message
re: quickform controller back button javascript issue Hi, I am having a difficulty getting a QuickForm's back button to work without trying to validate the fields on the current page in javascript. I followed the FAQ for QuickForm Controller on this. From the FAQ : "I use client-side validation. How do I switch it off for 'Back' button? Client-side validation is called by form's onSubmit handler, if you remove the handler, the validation will not run. Therefore you need to remove it if user clicks on 'Back' button. This can be achieved f.e. by adding the following as the button's onClick handler: this.form.onsubmit = null; return true;" I have added this as so (follows is part of rendered HTML of page 2 of my form) <input onclick="this.form.onsubmit=null; return true;" name="_qf_page2_back" value="&lt;&lt; Back" type="submit" /> and my form tag reads... <form action="index.php" method="post" name="page2" id="page2" target="_self" onsubmit="try { var myValidator = validate_page2; } catch(e) { return true; } return myValidator(this);"> and when i hit the back button, it asks me once to fill in a required field, then after OK is clicked, it DOES let me go back when I hit back again. So it is almost correct...but unsure how to fix this. The javascript makes sense to me, so I cannot figure it out - I am not too familiar with javascript though, and like quickform for its usefulness in that respect. From the validator code that QF adds, it seems that TRUE won't get returned if submit is passed the NULL value... function validate_page2(frm) { var value = ''; var errFlag = new Array(); var _qfGroups = {}; _qfMsg = ''; value = frm.elements['exclude'].value; var regex = /^[^().\/\*\^\?#!@$%+=,\"'><~\[\]{}]+$/; if (value != '' && !regex.test(value) && !errFlag['exclude']) { errFlag['exclude'] = true; _qfMsg = _qfMsg + '\n - Sorry please try letters only'; } value = frm.elements['budget'].value; if (value == '' && !errFlag['budget']) { errFlag['budget'] = true; _qfMsg = _qfMsg + '\n - Sorry, budget is required'; } value = frm.elements['budget'].value; var regex = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; if (value != '' && !regex.test(value) && !errFlag['budget']) { errFlag['budget'] = true; _qfMsg = _qfMsg + '\n - sorry, budget is numbers only'; } if (_qfMsg != '') { _qfMsg = 'Invalid information entered.' + _qfMsg; _qfMsg = _qfMsg + '\nPlease correct these fields.'; alert(_qfMsg); return false; } return true; } any help would be much appreciated! thanks Luke -- ~L~ lukebarker@gmail.com --------------------------------------- I'm doggone gonna be with Some real people... ( Rodgers & Edwards )

« previous php.pear.general (#21717) next »