php - Redirect to Homepage when password changed -
i working php , need page redirect if password has been changed successfully. presently changes password when click submit nil happens. kind of stuck on this, first time working php help appreciated please. below model code.
public function change_password($user_id, $hash) { $query = "update users set password=? user_id=?"; if($this->db->query($query, array($hash, $user_id))){ homecoming true; } else{ homecoming false; } } controller:
public function security_settings(){ $pass = $this->input->post('password', true); $cpass = $this->input->post('cpassword', true); $user_id = $this->user->user_id; if($pass==='' || $cpass==='') { echo '{"msg":"alert alert-danger","html":"passwords not match"}'; return; } if($pass!=$cpass) { echo '{"msg":"alert alert-danger","html":"passwords not match"}'; return; } $hash = $this->phpass->hash($pass); while(strlen($hash) < 20){ $hash = $this->phpass->hash($pass); } if($this->profile_model->change_password($user_id, $hash)) { echo '{"msg":"alert alert-info","html":"changes have been saved successfully"}'; } else { echo '{"msg":"alert alert-danger","html":"<b>error!</b> unable save changes"}'; } } and view:
<form class="form-horizontal" role="form" id="defform" method="post" action="<?php echo site_url('profile/security_settings') ?>"> <div class="form-group"> <label class="control-label col-md-3" for="password">new password</label> <div class="col-md-5"> <input type="password" class="form-control" id="password" name="password" placeholder="enter new password"> </div> </div> <div class="form-group"> <label class="control-label col-md-3" for="cpassword">confirm password</label> <div class="col-md-5"> <input type="password" class="form-control" id="cpassword" name="cpassword" placeholder="confirm new password"> </div> </div> <div class="form-group"> <label class="control-label col-md-3"></label> <div class="col-md-5"> <button type="submit" class="btn btn-primary">save changes </button> </div> </div> </form> here javascript code used ajax form submission:
<script type="text/javascript"> $().ready(function() { $('#defform').bootstrapvalidator({ message: 'this value not valid', fields: { password: { validators: { notempty: { message: 'the password required , can\'t empty' }, stringlength: { min: 8, max: 50, message: 'the password must more between 8 50 characters long' }, identical: { field: 'password2', message: 'the password , confirm not same' } } }, cpassword: { validators: { notempty: { message: 'the confirm password required , can\'t empty' }, stringlength: { min: 8, max: 50, message: 'the password must more between 8 50 characters long' }, identical: { field: 'password', message: 'the password , confirm not same' } } } } }); $('#defform').ajaxform({ datatype: 'json', success: function(response){ $('#info-well').removeclass().addclass(response.msg); $('#info-well').html(response.html); } }); });
similar msg , html add together 2 more values redirected , page illustration can like
'{"msg":".....","html":".....","redirect":1,"page":base_url()."/controller"} // if want redirect. and
'{"msg":".....","html":".....","redirect":0,"page":"#"} // if not want redirect. in js have
$('#defform').ajaxform({ datatype: 'json', success: function(response){ $('#info-well').removeclass().addclass(response.msg); $('#info-well').html(response.html); //you can set timeout here of 5 seconds user can read success message , append text redirecting to..... if(response.redirected==1) {window.location.href = response.page;} //this line redirect controller. } }); php codeigniter netbeans url-redirection ajaxform
No comments:
Post a Comment