Forum Moderators: open
I am using a very complicated submission form for a website (PHP/ MySQL) I am creating and beside the normal PHP validation, I use javascript to execute certain things that are otherwise hard to accomplish (chained selects, amounts based on user input on prev. page and some other things), all in order to make the process more understandable for the user
However, the process REQUIRES javascript (button onclick = this.form.submit() ) and I dont intend to change that, but it does pose me with a problem.
Ofcourse I can simply add some noscript content, but that is easily bypassed when a user temporarily disables javascript in the browser.
I know I could easily make something like I want with javascript, but that kinda defeats the purpose :p
any ideas?
Barring that possibility, your entire validation routine should exist as a single function which is called with an
onsubmitin the form tag. It can also be called with onclick and onblur and all the other stuff to happen "live," but you also can add the final check before submitting.
If your users start leaving the javascript disabled long enough to submit the form (circumventing the final check), then how about only enabling the submit button once the form is valid? You could have a <div id="validation"> that you use a constructed .innerHTML to list what steps remained to be valid then showed the submit button once everything was valid. If they disabled javascript at this point to go back and change things, then well, why do put up with these people at all? :)
well, some of the fields are optional, however, they do require a radio button to be checked in order to send along a value even if someone doesnt know a certain field ('unknown' or something like that)
I'd like all entries to look the same.
and there is another reason, cant think of it now though lol (its early, sue me :p ) and besides, it would be neat imo
i have a javascript function which draws a html select each time a user presses a button, its defined as an array (< select name = "something[]" )
the values are populated by a MySQL DB query and the javascript is made by PHP.
This works perfectly sofar.
However, one of the selects is hardcoded, the others are dynamic and when submitting the form, it only seems to wanne post the hardcoded one, not the dynamic ones created via innerHTML
am I trying something that is impossible?
On the subject of:
Testing to see whether JS has been temporarily disabled
Here's a way. Very simple really.
- Get the start time;
- loop at regular (2 sec) intervals;
- update current time;
- if difference is, say, 2 secs greater than the delay..
(Got to allow for heavy processes that may stall scripting. This also rules out use of modal prompts & dialogs)
..then set the cheat.flag to true.
It my test, turning script off at some point seems to cause scripting to sleep. It carries on when reactivated. All state is maintained. If this doesn't happen, the proof of the pudding is still the diff between current time and the last recorded time.
This does require that JS is on to start with. So you'd need the form inputs unavailable at first if scripting is off.
-----------------------------------------
k = -1; // just for demovar cheat =
{
flag : false,
t0 : new Date().getTime(),
timer: null,check: function()
{
var t1 = new Date().getTime();
var diff = t1 - this.t0;
this.t0 = t1;
/*--- just for demo ----------------------------------*/
if(document.getElementById("d0"))/* when ready*/
document.getElementById("d0").innerHTML = ++k +': '+diff;
/*----------------------------------------------------*/
if(diff > 4000){
this.flag = true;
/**/alert("cheat!");
clearTimeout(this.timer);
}},
start: function(){ this.timer = setInterval('cheat.check()',2000)}
}cheat.start();
-----------------------------------
ah yes. You'll need a div: id="d0" for the demo output;
and sorry if i am late and have missed a point that makes what im saying irrelivant.
but i would say cant rely on js for form validation, its nice , and most of the time it is used by people with js turned on, but i woudl say all validation shoudl be done on the server side aswell. simply because you cant count on js being turned on, or fiddled with whist entering form information.
afew simple initial checks in the server side validation, and each submission need not hog valuable resources (?)
just my tuppence.
:)