1
我正在使用此代碼來請求新用戶在首次登錄時更改其密碼。因此,這裏是它在彈出首次登錄後打開我的表格:在表單中提交php調用jquery函數
<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!
如果你想避免重定向使用** AJAX ** – NID