I am trying to make multi step form using ajax everithing is working fine but when I enter wrong otp to verify then obviously it will show Invalid otp and after then when I enter correct otp whithout refreshing page otp is verified successfully but next step form is not showing. In php code is like this if (isset($POST['VBPNOTP'])) {then insert data in data base code will be here}else{echo 0;}
PHP CODE
if (isset($POST['VBPNOTP'])) {
$OTP=$POST['OTP'];
$data['email'] = $_SESSION['email'];
$sql = "select * from user where email = :email limit 1";
$che开发者_JS百科cking = $db->read($sql,$data);
$data['otp'] = $checking[0]->otp;
if ($data['selotp'] == $OTP) {
$data['sel']= 0;
$data['email'] = $_SESSION['email'];
$query = ("UPDATE user SET otp = :otp WHERE email = :email");
$result2 = $db->write($query,$data);
if($result2) {
echo 1;
}else{
echo 0;
}
}else{
echo 0;
}
}
AJAX CODE
$(document).on("click","#vfotp",function verify_code(e) {
var OTP = $("#OTP").val();
//var regexPhone = /^[6789][0-9]{9}$/;
$.ajax({
url: "<?= BASEURL ?>ajax",
type: "POST",
datatype:"JSON",
data:{OTP:OTP},
success: function (data) {
console.log(data);
if(data==1){
console.log('good');
$("#smpv")[0].reset();
$('#phoneif').removeClass('active');
$('#storeif').addClass('active');
$('.step-progress-list-eiwgzy:nth-child(1)').removeClass('current-item');
$('.step-progress-list-eiwgzy:nth-child(2)').addClass('current-item');
//$("#smpv")[0].reset();
}else{
console.log('pumpoo')
$(".permsgOTP").html("OTP is Invalid");
$('#VBPNOTP').css({'border-color':'red'});
}
});
e.preventDefault();
});
精彩评论