| Luke Barker 2005-10-31, 6:59 pm |
| 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 =3D null; return true;"
I have added this as so (follows is part of rendered HTML of page 2 of my f=
orm)
<input onclick=3D"this.form.onsubmit=3Dnull; return true;"
name=3D"_qf_page2_back" value=3D"<< Back" type=3D"submit" />
and my form tag reads...
<form action=3D"index.php" method=3D"post" name=3D"page2" id=3D"page2"
target=3D"_self" onsubmit=3D"try { var myValidator =3D 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 =3D '';
var errFlag =3D new Array();
var _qfGroups =3D {};
_qfMsg =3D '';
value =3D frm.elements['exclude'].value;
var regex =3D /^[^().\/\*\^\?#!@$%+=3D,\"'><~\[\]{}]+$/;
if (value !=3D '' && !regex.test(value) && !errFlag['exclude']) {
errFlag['exclude'] =3D true;
_qfMsg =3D _qfMsg + '\n - Sorry please try letters only';
}
value =3D frm.elements['budget'].value;
if (value =3D=3D '' && !errFlag['budget']) {
errFlag['budget'] =3D true;
_qfMsg =3D _qfMsg + '\n - Sorry, budget is required';
}
value =3D frm.elements['budget'].value;
var regex =3D /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (value !=3D '' && !regex.test(value) && !errFlag['budget']) {
errFlag['budget'] =3D true;
_qfMsg =3D _qfMsg + '\n - sorry, budget is numbers only';
}
if (_qfMsg !=3D '') {
_qfMsg =3D 'Invalid information entered.' + _qfMsg;
_qfMsg =3D _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 )
|