1

I have 2 fields - Password and Confirm Password If I enter a value in confirm password field first and then enter value into password field, message saying "password matched" if matching and "password does'nt match" if mismatching should be displayed. But presently it is not working for me. Could you please help me in fixing this issue

Here is the code - Ajax Call

$aVal = $this->get('val');

        Phpfox::getService('confirmpassword')->password($aVal['password'], $aVal['password_confirm']);

        if (Phpfox_Error::isPassed()) {
            $this->call('$(\'#js_password_match\').css(\'background-color\', \'#00AA00\');');
            $this->call('$(\'#js_password_match\').css(\'padding\', \'1.05px\');');
           // $this->call('$(\'#js_password_match\').css(\'margin-left\', \'5px\');');
            $this->call('$(\'#js_password_match\').html(\'' . Phpfox::getPhrase('confirmpassword.password_matched') . '\');');

            return true;
        }

        $aErrors = Phpfox_Error::get();

        $this->call('$(\'#js_password_match\').css(\'background-color\', \'#DD0000\');');
        $this->call('$(\'#js_password_match\').css(\'padding\', \'1.05px\');');
        //$this->call('$(\'#js_password_match\').css(\'margin-left\', \'5px\');');
        $this->call('$(\'#js_password_match\').html(\'' . $aErrors[0] . '\');');

and Service call -

public function password($sPass, $sConfirm)
        {
            if((strlen($pass) || strlen($sConfirm)) != 0)
            {   
                if(strcmp($sPass, $sConfirm) != 0)
                {
                    Phpfox_Error::set(Phpfox::getPhrase('confirmpassword.password_does_not_match'));
                }
            }
            else 
            {
                Phpfox_Error::set(Phpfox::getPhrase('confirmpassword.empty_password_field'));
            }

            return $this;
        }
Steffi
  • 255
  • 1
  • 3
  • 14
  • Hum... `if((strlen($sPass) != 0 && strlen($sConfirm)) != 0)`?? I changed the `$pass` for `$sPass` and added a `!= 0`, I also changed the `||` for `&&` because both need to not be empty to be the same. – Sebastien Jul 23 '14 at 19:12
  • This is not working @Sebastien Main concept is i will be entering confirm password field first the the password field. The message "pwd matched" should be displayed, if pwd matches and the message "pwd doesnt" match should be displayed if mismatches. – Steffi Jul 25 '14 at 06:55
  • Could you help me out in, if the requirement is - If confirm pwd field contains some value, and if I try to enter some value in pwd field, then confirm pwd field should get emptied. – Steffi Jul 25 '14 at 06:57
  • You will have to do some javascript/jquery something in the lines of `$('#passwordFieldID').on('focus', function(){$('#ConfirmFieldsID').val('')});` – Sebastien Jul 25 '14 at 12:47

1 Answers1

0

I'll just copy the comments here so future reference know what has been done:

Hum...if((strlen($sPass) != 0 && strlen($sConfirm)) != 0)?? I changed the $pass for $sPass and added a != 0, I also changed the || for && because both need to not be empty to be the same. – Sebastien

This is not working @Sebastien Main concept is i will be entering confirm password field first the the password field. The message "pwd matched" should be displayed, if pwd matches and the message "pwd doesnt" match should be displayed if mismatches. – user3630920

Could you help me out in, if the requirement is - If confirm pwd field contains some value, and if I try to enter some value in pwd field, then confirm pwd field should get emptied. – user3630920

You will have to do some javascript/jquery something in the lines of $('#passwordFieldID').on('focus', function(){$('#ConfirmFieldsID').val('')}); – Sebastien

Sebastien
  • 1,308
  • 2
  • 15
  • 39
  • Emptying the Confirm Password is working, but the message is not displayed properly. If I enter a value "test" in confirm password field and try to enter "test" in password field, confirm password field gets emptied but a message saying enter a value in confirm field is not displayed. @Sebastien – Steffi Jul 31 '14 at 04:30
  • @user3630920 could you add an edit to your post with the new code? So I can see what you have done ? – Sebastien Jul 31 '14 at 12:06