User Form error checking

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

User Form error checking

 
0
  #1
Mar 2nd, 2007
Hey everyone, I need some advice. I have a simple user form. Name, email, comments, blah blah blah.

Currently for error checking, in my code, if the user inputs something invalid or doesn't fill out a required field, I redirect them to another page that tells them the error, then they have to hit the back button to go back and fix it.

I'd like to make this process a little easier for the user. I've seen forms where if you miss a required field or something, it simply brings the form back up and at the top in red letters will tell you to fill in all the required fields or something, and then have like a red star next to those fields.

I'm sure if I sat around for a few hours I could come up with a real clunky, code-heavy way of doing this, but I was wondering if you all can give me some ideas. An easy way of doing this? I have a moderate understanding of php, so I know most of the basic functions and things. And when I come across one I don't know, I'll learn it, so bring it on.
Ideas?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: User Form error checking

 
0
  #2
Mar 2nd, 2007
No need to send them to another page. Data validation is easy to do.

1) Receive the POSTed form data (top of the file)
2) Validate it. Put errors into an array so you can echo them out later
3) Check to see if you found any errors. If not, do whatever you want to do with the data.
4) If there are error, redisplay the page and list the errors so the users knows what they did wrong.

This method also allows you to repopulate the form fields if there is an error so they don't have to type it in again.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: User Form error checking

 
0
  #3
Mar 2nd, 2007
Originally Posted by stymiee View Post
No need to send them to another page. Data validation is easy to do.

1) Receive the POSTed form data (top of the file)
2) Validate it. Put errors into an array so you can echo them out later
3) Check to see if you found any errors. If not, do whatever you want to do with the data.
4) If there are error, redisplay the page and list the errors so the users knows what they did wrong.

This method also allows you to repopulate the form fields if there is an error so they don't have to type it in again.
Thanks for that. I think I get what you're going at. And I think I was able to Google something that also might help, right along the same lines of what you're saying. I'll let you know how it goes.
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 16
Reputation: WhiteLeo is an unknown quantity at this point 
Solved Threads: 2
WhiteLeo's Avatar
WhiteLeo WhiteLeo is offline Offline
Newbie Poster

Re: User Form error checking

 
0
  #4
Mar 3rd, 2007
Another idea is to also include a javascript validation. There are plenty of tutorials found through google. Just look up "Javascript Form Validation".

That way when the button is clicked, the form is instantly checked and a message displayed at that moment without a page having to be reloaded.

However, you still should included some server side validation, using php. The javascript is jut to make it easier for the person. The php is there incase the person gets around the javascript.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: User Form error checking

 
0
  #5
Mar 3rd, 2007
Originally Posted by WhiteLeo View Post
Another idea is to also include a javascript validation. There are plenty of tutorials found through google. Just look up "Javascript Form Validation".

That way when the button is clicked, the form is instantly checked and a message displayed at that moment without a page having to be reloaded.

However, you still should included some server side validation, using php. The javascript is jut to make it easier for the person. The php is there incase the person gets around the javascript.
Very good idea! I'll take a look into that as well.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 3
Reputation: csscart is an unknown quantity at this point 
Solved Threads: 0
csscart csscart is offline Offline
Newbie Poster

Re: User Form error checking

 
0
  #6
Mar 4th, 2007
Originally Posted by stymiee View Post
No need to send them to another page. Data validation is easy to do.

1) Receive the POSTed form data (top of the file)
2) Validate it. Put errors into an array so you can echo them out later
3) Check to see if you found any errors. If not, do whatever you want to do with the data.
4) If there are error, redisplay the page and list the errors so the users knows what they did wrong.

This method also allows you to repopulate the form fields if there is an error so they don't have to type it in again.
Don't forget to sanitize and validate the data. You didn't say if you are storing in DB or emailing, but the PHP mail() function can be used by spammers if you're not careful with your data.

http://www.securephpwiki.com/index.php/Email_Injection
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: User Form error checking

 
0
  #7
Mar 4th, 2007
I guess you missed item number 2?

2) Validate it. Put errors into an array so you can echo them out later
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: User Form error checking

 
0
  #8
Mar 5th, 2007
Originally Posted by csscart View Post
Don't forget to sanitize and validate the data. You didn't say if you are storing in DB or emailing, but the PHP mail() function can be used by spammers if you're not careful with your data.

http://www.securephpwiki.com/index.php/Email_Injection
I'm storing the info in a mysql database, but also sending a copy of it to my email address. However, that should be hard for spammers to fake, since the user needs a special code verified before they can submit the form. Basically, the user puts in the code, which lets them to the main form. Then when they actually submit the form, the script again makes sure that the code is valid, then processes the info.

And FYI, your help has worked. I'm going it the way you said, submitting the form to itself, and I have a variable that is stored, that is at first set to nothing. Any errors that pop up append themselves to the variable. Then if there are errors, it shows the form with that variable at the top. Working splendidly.
Thanks!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: User Form error checking

 
0
  #9
Mar 6th, 2007
Nathan - just an idea - you could display the error messages next to the wrong fields, while the correct fields data is automatically entered into the correct field, so the user does not have to fill in all the fields. Or, even better - you can show only the wrong fields, that have invalid data, instead of showing all, and still error messages to be just beside the erroneous field.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC