form validation issue
 |
|
September 17th, 2003, 12:28 PM
|
#1
|
|
Senior Member
Join Date: Oct 2001
Location: Utah
Posts: 551
|
Not exactly a php issue, but may fit best in this category
Ok, here's the problem...
I have a few forms(register, login, etc)
I validate them with javascript(well, the first time) before sending it to the php page to process.
I do this by calling this function from the FORM tag
onSubmit="return checkForm(this)
This functions verifies everything is completed satisfactory and then returns true if it is, and false if not.
here's the last bit
if (errorMsg=="") {
return true;
}
else
{
//document.write (errorMsg);
alert(errorMsg);
return false;
the problem is, I don't like popup boxes with that alert. I'd rather write it to somewhere in the document. Obviously using document.write creates a new page, and you no longer use the form. So, I should be able to use DHTML, style sheets, whatever you call it to write or update the innerHTML on a part of the form. I was thinking at the bottom, in red, saying you left something out, etc.
Whenever I put something like that in, it submits the form, and gets caught on the php error trapping. But, I want it to stay on the form page, display what's wrong, not clear all the fields, and let them fix it and try to submit again. (without having to go back, and not have the fields,(or me not coding it all into session or anything)
Thanks for any help, feel free to ask for any clarification.
dragonb
p.s.
this function works...
function changed(inp) {
span = document.getElementById("notepass");
input1 = document.forms["registerform"]["frmPassword"];
input = document.forms["registerform"]["frmPassword2"];
if (input.value != input1.value) {
span.innerHTML = '<strong><font color="red">Sorry, Passwords do not match.</font></strong>';
} else {
span.innerHTML = "";
}
}
It is called onblur of the password boxes to make sure the 2 match.
|
|
|
September 18th, 2003, 12:58 AM
|
#2
|
|
Banned
Join Date: Oct 2001
Posts: 447
|
sounds to me you want a multi-purpose page?
not sure want you are asking, so what's the problem, exactly?
at the very least use your client side javascript validation.
if you don't like the "dialog"(popups are different, they when browser(client) opens new browser window...) generated by the 'alert()', then don't use the client side javascript.
btw, if client side scripting is of interest, you can validate your form client side with javascript and dhtml, BUT:
only work with MS stuff, versions of MS stuff an issue.
anyway, you might not understand any of that so:
the PHP way, server side scripting/validation/whatever, is not hard, but not simple. It goes like this:
Code:
create a "submit.php" //call it what you want.
if user has not submitted form, then show form, else
user has never seen/submitted form!
if user submit form, validate the form, all fields, btw.
if form fails, return the form with submitted values that
pass validation, highlight (show user) which fields fail.
//add any text before/after/in between???
else, form passed, process, return results to user.
???s
|
|
|
September 18th, 2003, 01:13 AM
|
#3
|
|
Senior Member
Join Date: Oct 2001
Location: Utah
Posts: 551
|
yea, that wasn't 100% clear what I explained...
Anyway, yea I understand what you are saying, and I've done that before, checking submit, reloading passed fields, etc.
It's just not quite as elegant, although it is all done in php(or asp)
I guess the real question is, why does it submit the form and continue when I put in a dhtml type statement to change/add text to the page, and return false. BUT, doesn't submit the form if I do the alert and then return false.
(agreed, alert isn't a popup, popups are even more annoying)
thanks for helping me clarify...
so here it is in pseudo code
alert();
return false
//doesn't submit the form and doesn't continue on to next php page
span.innerhtml = "new text"
return false
//submits the form and continues on to the next php page(where the errors are caught, but then user has to go back and re-enter all fields...or like you suggested I pass them back from there and refill them in.)
thx for the help so far.
dragonb
|
|
|
September 19th, 2003, 01:56 AM
|
#4
|
|
Banned
Join Date: Oct 2001
Posts: 447
|
Quote:
|
Anyway, yea I understand what you are saying, and I've done that before, checking submit, reloading passed fields, etc.
|
you have?
Quote:
|
...It's just not quite as elegant...
|
how would you know?
your pseudo code, is so pseudo like?
there is client, and there is server. much to learn.
|
|
|
September 19th, 2003, 02:21 AM
|
#5
|
|
Senior Member
Join Date: Oct 2001
Location: Utah
Posts: 551
|
got if figured. Asked a guru friend of mine.(sometimes it so much easier to explain in person)
It's apparently a javascript bug. The work around is to set focus to a form field element before making any dhtml changes, and then the form doesn't submit. Which works great anyway, because you can set the focus to the field that has the error.
dragonb
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
Most Active Discussions
|
|
|
|
|
Recent Discussions 
|
|
|
|
|
|