sweetalert 2.0 ajax,Sweetalert2 input validation with AJAX

I'm using sweetalert2 to set-up multiple inputs as modal (with swal mixin), and I need to verify in server-side if values sent are equal to the ones in database. As example I'm using just a constant value in the .php file. Here's my code:

{

onBeforeOpen: function (dom) {

dom.getElementsByClassName('swal2-input')[0].style = "display: none";

},

html:

"

" +

"

"+

"" +

"Por favor ingresa el codigo de verificacion NUIP "+

"que hemos enviado a tu celular" +

""+

"

" +

"" +

"" +

"" +

"" +

"

" +

"

"+

"

",

inputValidator: function() {

var nums = Object.values(document.getElementsByClassName("inp-num"));

for(var i = 0; i < nums.length; i++) {

if(!nums[i].value) {

return 'Ingresa el codigo completo';

}

}

$.ajax({

type: "POST",

url: "php/confirma_datos.php",

data: {

"one": $("#num-1").val(),

"two": $("#num-2").val(),

"three": $("#num-3").val(),

"four": $("#num-4").val(),

},

success : function(response) {

if (response == 'true') {

swal('hola');

return 'OK';

} else {

console.log('no coinciden');

}

},

});

},

preConfirm: function () {

return [

$("#num-1").val(),

$("#num-2").val(),

$("#num-3").val(),

$("#num-4").val(),

]

},

},

And in the server side I have.

$nuip_comp = "1234";

$nuip = $_POST['one'] . "" . $_POST['two'] . "" . $_POST['three']. "" . $_POST['four'] ;

if($nuip_comp == $nuip) {

echo 'true';

} else {

echo 'false';

}

I want to prevent the modal to go to the next step until the values are equal. Any idea on how to do this?

Thanks!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值