Results 1 to 2 of 2
  1. #1
    KingdomX is offline Member
    Join Date
    Dec 2011
    Rep Power

    Post 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:
    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);
    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.

    Thanks in advance!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

    Default 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

  1. Returning multiple results in JDBC
    By mDennis10 in forum New To Java
    Replies: 7
    Last Post: 08-23-2011, 04:38 PM
  2. Struts action form not returning object
    By niteangell21 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 02-08-2011, 06:50 PM
  3. Method Arrays's: Returning multiple values
    By noobForever in forum New To Java
    Replies: 6
    Last Post: 11-02-2010, 01:07 PM
  4. Returning Multiple Value's
    By Hollywood_99 in forum New To Java
    Replies: 8
    Last Post: 10-22-2010, 10:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts