Results 1 to 2 of 2
Thread: Returning multiple form errors
- 01-19-2012, 09:43 PM #1
Member
- Join Date
- Dec 2011
- Location
- Brazil
- Posts
- 26
- Rep Power
- 0
Returning multiple form errors
The idea:
A user fills a form and it goes through several checks on server side after a form submit. Let's say we have 4 different checks from the form:
1 - Checks the password pattern.
2 - Checks the password length.
3 - Checks the password for invalid characters like ⌐ or ☼.
4 - Checks if both password fields match
Let's say that all of these checks HAVE failed, so then we must return the user to the form and inform the checks he has failed on.
The problem:
I'm currently using the session to return the value to the form through an error string. But this will just be hell to manage. Suppose the user leaves the page... i'll have to unset that session, if i don't, he could click on a link to go to the form and it would display the errors all over again.
The code:
I could really use some ideas on how to do this. I've been searching this for two days and couldn't find a way to return this to the form.Java Code:String errors = ""; // Checks the user's e-mail pattern if ( SecureInputs.patternEmail(mail1) ){ errors += "<li> {invalidEmail}</li>"; } // Checks if both e-mail fields match if ( SecureInputs.areEmailsDifferent(mail1, mail2) ){ errors += "<li> {emailFieldsDontMatch}</li>"; } // Checks the user's password pattern if ( SecureInputs.patternPassword(pw1) ){ errors += "<li> {passwordInvalidCharacter}</li>"; } // Checks the user's password length if ( SecureInputs.passwordLength(pw1) ){ errors += "<li> {passwordBelowLength}</li>"; } // Checks if both password fields match if ( SecureInputs.arePasswordsDifferent(pw1, pw2) ){ errors += "<li> {passwordFieldsDontMatch}</li>"; } // Checks if the user has agreed to the privacy terms if ( this.agreeCheck(agree) ){ errors += "<li> {doesntAgreeTerms}</li>"; } // If any errors were found, redirects the user back to the form if( !"".equals(errors) ){ Session.session.setAttribute("errors", errors); Main.redirect(Main.registerPageLoc); }
Thanks in advance!
- 01-20-2012, 03:23 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Returning multiple form errors
In such situation what I am doing is simply use a URL parameter. On the login page load validate the parameter and display the relevant message. Reason was, as you feel, managing the sessions is quite difficult in most of the situations.
Similar Threads
-
Returning multiple results in JDBC
By mDennis10 in forum New To JavaReplies: 7Last Post: 08-23-2011, 03:38 PM -
Struts action form not returning object
By niteangell21 in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 02-08-2011, 05:50 PM -
Method Arrays's: Returning multiple values
By noobForever in forum New To JavaReplies: 6Last Post: 11-02-2010, 12:07 PM -
Returning Multiple Value's
By Hollywood_99 in forum New To JavaReplies: 8Last Post: 10-22-2010, 09:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks