Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Mistake? careless?

    When i try to enter different password in my form, "Confirmation password is different" popped up, but it still submit the form.
    Any idea what's wrong?

    Code:
    <script type="text/javascript">
    
    	   dojo.require("dojo.parser");
           dojo.require("dijit.form.ValidationTextBox");
    	   dojo.require ("dijit.form.Form");
    	   dojo.require("dijit.form.CheckBox");
    	   dojo.require ("dijit.form.FilteringSelect");
    	   dojo.require ("dijit.form.TextBox");
    	   
    	   
    	   function checkPw(formFields) {
              if (formFields.confirmuPass != formFields.uPass2)
    			alert("Confirmation password is different.");
    			
    			
    }       	   
    
    
    	   
    	     function submitIfValid(valid)
    {
    if (valid) {
    document.signup.submit()
    } else {
    		alert('Not all fields are valid');
    		
     }	
    }
    
    function both(formfields, valid) {
    checkPw(formfields);
    submitIfValid(valid);
    
    }
    
    </script>
    and this is my form.

    Code:
    <form name="signup" dojotype="dijit.form.Form" action = 'do_signup.php' method='post' 
    enctype='multipart/form-data'  execute="both(arguments[0], this.isValid());">
    
    <tr>
    			<td>Password</td>
    			<td><input type = 'password' name = 'uPass'
        			dojoType="dijit.form.ValidationTextBox"
    				
    				required="true"
    				invalidMessage="Please type a password" />*</td>
    		</tr>
    		<tr>
    			<td>Confirm Password</td>
    			<td><input type = 'password' name = 'uPass2'
    	            dojoType="dijit.form.ValidationTextBox"
    				required="true"
    				invalidMessage="Please confirm your password" />*</td>
    		</tr>
    Help appreciated.
    Last edited by rockbluster; 07-23-2009 at 12:40 PM. Reason: easier to read

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    YOu have to change your function like this:

    Code:
    function checkPw(formFields) 
    {
              if (formFields.confirmuPass != formFields.uPass2)
              {
                  valid = false;
                  alert("Confirmation password is different.");
               }
    			
    			
    }
    I suppose that you have created a global variable named valid that you are retrieving using the method isValid();

    When the validation is not complete make sure to set it to false.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Code:
    alert("Confirmation password is different.");
    return false;


    It is your responsibility to die() if necessary….. - PHP Manual

  • #4
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    Code:
    function checkPw(formFields) {
       if (formFields.confirmuPass != formFields.uPass2) {
          alert("Confirmation password is different.");
          return false;
       } else {
          return true;
       }			
    }
    
    ...............
    
    function both(formfields, valid) {
       if (checkPw(formfields))
          submitIfValid(valid);
    }

    P.S. O, I'm third in order... =)
    Last edited by Amphiluke; 07-22-2009 at 07:55 PM.
    I am still learning English

  • #5
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    To be done in a more accurate way, I would take the code of Amphiluke and change it to this:
    Code:
    function checkPw(formFields) {
       if (formFields.confirmuPass != formFields.uPass2) {
          alert("Confirmation password is different.");
          return false;
       } else {
          return true;
       }			
    }
    
    ...............
    
    function both(formfields, valid) 
    {
          submitIfValid(checkPw(formfields));
    }

  • #6
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi guys, thanks for replying.
    Unfortunately, it's still not working.

    This time, the form will not submit when the password is wrong, but when the password matches, "Confirmation password is different." still pops out.

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Should this:

    Code:
    if (formFields.confirmuPass != formFields.uPass2) {
    not be:

    Code:
    if (formFields.uPass != formFields.uPass2) {

  • #8
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Should this:

    Code:
    if (formFields.confirmuPass != formFields.uPass2) {
    not be:

    Code:
    if (formFields.uPass != formFields.uPass2) {
    Thats right. i put

    Code:
    if (formFields.confirmuPass != formFields.uPass2) {

  • #9
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Your code should be like this:

    Code:
    if (formFields.uPass.value != formFields.uPass2.value) {

  • #10
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ckeyrouz View Post
    Your code should be like this:

    Code:
    if (formFields.uPass.value != formFields.uPass2.value) {
    After i try changing to yours, the form submitted even though the password is different.

  • #11
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    So many changes where done.
    Could you please post the latest code you have?

  • #12
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Right now :


    Code:
    <script type="text/javascript">
    
    	   dojo.require("dojo.parser");
           dojo.require("dijit.form.ValidationTextBox");
    	   dojo.require ("dijit.form.Form");
    	   dojo.require("dijit.form.CheckBox");
    	   dojo.require ("dijit.form.FilteringSelect");
    	   dojo.require ("dijit.form.TextBox");
    	   
    	   
    	   function checkPw(formFields) {
       if (formFields.confirmuPass != formFields.uPass2) {
          alert("Confirmation password is different.");
          return false;
       } else {
          return true;
       }			
    }
     	   
    
    
    	   
    	     function submitIfValid(valid)
    {
    if (valid) {
    document.signup.submit()
    } else {
    		alert('Not all fields are valid');
    		
     }	
    }
    
    function both(formFields, valid) 
    {
          submitIfValid(checkPw(formFields));
    }
    
    </script>

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Code:
    var valid = true;
    function checkPw(formFields) {
    if (formFields.confirmuPass != formFields.uPass2) {
    alert("Confirmation password is different.");
    valid = false;
    }
    return valid;			
    }
    
    function submitIfValid(valid) {
    if (valid) {
    document.signup.submit();
    } 
    else {
    alert('Not all fields are valid');
    return false;		
    }	
    }
    Last edited by Philip M; 07-22-2009 at 08:51 PM.

  • #14
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    var valid = true;
    function checkPw(formFields) {
    if (formFields.confirmuPass != formFields.uPass2) {
    alert("Confirmation password is different.");
    valid = false;
    }
    return valid;			
    }
    
    function submitIfValid(valid) {
    if (valid) {
    document.signup.submit();
    } 
    else {
    alert('Not all fields are valid');
    return false;		
    }	
    }
    hmmmm...... It is still not working.

  • #15
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    where is the html object named confirmuPass .
    Cannot see it in the code you posted.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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