2017-07-28 9 views
1

私はこのコードを使用して、新規ユーザーに最初のログイン時にパスワードを変更するよう要求しています。そこでここでは最初のログイン後のポップアップで開く私のフォームです:フォームでjquery fuctionを呼び出してください。

<div class="modal" id="change-password-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" data-keyboard="false"> 
      <div class="modal-dialog modal-lg" role="document" style="top:20%"> 
      <div class="modal-content content-align"> 
       <div class="modal-header"> 
       <h3 class="modal-title text-center modal-title-col">Change your password</h3> 
       </div> 
       <div class="modal-body"> 
       <form id="change-password" class="ns-form half-width" method="post" action="/profile/changepassword"> 
        <?php if(empty($_POST) || isset($exc)): ?> 
        <label> 
        <input class="input-box" type="password" name="curr_pwd" required="required" maxlength="64" placeholder="Current Password" required="required" /> 
        <?php if(isset($exc) && $exc->getCode() == eInfo::INVALID_CREDENTIALS): ?> 
         <span class="error msg-block bottom"> 
         <?php echo stripslashes($exc->getMessage()); ?> 
         </span> 
        <?php endif; ?> 
        </label> 
        <label> 
        <input class="input-box" type="password" name="new_pwd" required="required" maxlength="64" placeholder="New Password" /> 
         <?php if(isset($exc) && $exc->getCode() == eInfo::INVALID_PASSWORD): ?> 
         <span class="error msg-block bottom"> 
          <?php echo stripslashes($exc->getMessage()); ?> 
         </span> 
         <?php endif; ?> 
        </label> 
        <label> 
        <input class="input-box" type="password" name="retype_pwd" 
          required="required" maxlength="64" placeholder="Re-type Password" /> 
        </label> 
        <center> <input type="submit" value="Change" class="change-button" id="change-button" /> </center> 
        <?php endif; ?> 
       </form> 
       <?php if(!empty($_POST) && !isset($exc) && isset($message)): ?> 
        <br/> 
        <strong><?php echo $message; ?></strong> 
        <br/> 
        <center><a href="/">Go home</a></center> 
       <?php endif; ?> 
       </div> 
       </div> 
      </div> 
      </div> 
     </div> 

それは私がアクションで書かれている/ CHANGEPASSWORDをプロファイルするために私を取る関数を提出の上に私をクリックします。私は私のフォームが他のページにリダイレクトされないようにポップアップでのみ提出したい。コントローラで

プロファイル/ CHANGEPASSWORD機能は

public function changepassword() { 
     User::authenticate(); 
     $this->log->debug("Inside " . __METHOD__ . "()..."); 

     $this->template->title = 'ChangePassword - '.TITLE_SUFFIX; 

     if(!empty($_POST)) { 
      try { 
       $allowed = array('curr_pwd', 'new_pwd', 'retype_pwd'); 
       if($allowed != array_keys($_POST)) { 
        loadException('InvalidFormSubmissionException'); 
        throw new \InvalidFormSubmissionException(); 
       } 

       User::validatePassword($_POST['new_pwd']); 

       if($_POST['new_pwd'] !== $_POST['retype_pwd']) 
        throw new model\exceptions\user\InvalidPasswordException('Passwords do not match!'); 

       if($_POST['curr_pwd'] === $_POST['new_pwd']) 
        throw new model\exceptions\user\InvalidPasswordException('Current password and new password should not be same!'); 

       $userService = new model\UserService(); 
       if(!($user = $userService->verifyPasswordForUser($_SESSION['userId'], $_POST['curr_pwd']))) { 
        loadException('user/InvalidCredentialsException'); 
        throw new model\exceptions\user\InvalidCredentialsException('Wrong password!'); 
       } 
       /*var $user User */ 
       $user->setPassword(md5($_POST['new_pwd'])); 
       $user->getPwdUpdated(1); 
       $_SESSION['pwd_updated']=1; 
       $userService->update($user); 
       $this->template->message = 'Your password has been changed.'; 
      } catch(model\exceptions\user\InvalidCredentialsException $e) { 
       $this->log->debug($e->getMessage()); 
       $this->template->exc =$e; 
      } catch (\InvalidFormSubmissionException $e) { 
       $this->log->debug($e->getMessage()); 
       $this->template->exc = $e; 
      } catch(model\exceptions\user\InvalidPasswordException $e) { 
       $this->log->debug($e->getMessage()); 
       $this->template->exc = $e; 
      } catch(\Exception $e) { 
       $this->log->debug($e->getMessage()); 
       $this->template->exc = $e; 
      } 
     } 
     $this->log->debug("Peak memory usage in " . __METHOD__ . " = " . (memory_get_peak_usage(TRUE)/1024) . " KB"); 
     $this->template->setLayout('profile'); 
     $this->template->show(); 
    } 

これは、基本的な少し質問ですが、私はit.THANKSを行う方法がわかりません!

+1

リダイレクトの使用を避けたい場合** AJAX ** – NID

答えて

0

フォームを自分のページに送信できるように、changepasswordのコードを自分のページに移動して、リダイレクトする必要がないようにするか、AJAXを使用する必要があります。