»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 09-17-2003, 09:28 AM   #1 (permalink)
Registered User
 
Join Date: Oct 2001
Location: Utah
Posts: 543
dragonb is on a distinguished road
form validation issue

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.

dragonb is offline   Reply With Quote
Old 09-17-2003, 09:58 PM   #2 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
qball is on a distinguished road
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
qball is offline   Reply With Quote
Old 09-17-2003, 10:13 PM   #3 (permalink)
Registered User
 
Join Date: Oct 2001
Location: Utah
Posts: 543
dragonb is on a distinguished road
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
dragonb is offline   Reply With Quote
Old 09-18-2003, 10:56 PM   #4 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
qball is on a distinguished road
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.
qball is offline   Reply With Quote
Old 09-18-2003, 11:21 PM   #5 (permalink)
Registered User
 
Join Date: Oct 2001
Location: Utah
Posts: 543
dragonb is on a distinguished road
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
dragonb is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 12:54 AM.