Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在php中调用表单提交的jquery函数_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 在php中调用表单提交的jquery函数

Javascript 在php中调用表单提交的jquery函数,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我使用此代码请求新用户在首次登录时更改其密码。这是我的表单,第一次登录后会弹出: <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

我使用此代码请求新用户在首次登录时更改其密码。这是我的表单,第一次登录后会弹出:

<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中的代码移动到表单所在的页面,这样您就可以将表单发送到它自己的页面,因此不需要重定向,或者必须使用。

如果要避免重定向,请使用AJAX如果要避免重定向,请使用AJAX
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();
    }