javascript - Call jquery fuction on form submit in php -
i using code request new user change password on first login. here form opens in popup after first login:
<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 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>
when click on submit function takes me profile/changepassword have written in action. want form submit in popup not redirect other page.
profile/changepassword function in controller
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 not match!'); if($_post['curr_pwd'] === $_post['new_pwd']) throw new model\exceptions\user\invalidpasswordexception('current password , new password should not 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's basic little question don't know how it.thanks!
either move code in changepassword page form in, can send form own page , therefore no redirection needed, or you'll have use ajax.
Comments
Post a Comment