<form name="submissions" method="POST" id="formx" action="javascript:void(null);" onsubmit="call()">
<div class="form-group form_flex phone_code">
<label>Для начала подтвердите свой действующий номер телефона<span class="req">*</span></label>
<div class="msg msg-custom pnel">
<input id="phone_require" type="text" name="phone_require" placeholder="Номер телефона" class="form-control phone_input" required><br>
<input onclick="send_form()" id="go_phone" type="button" name="submit" class="btn btn-success phone_bt" value="Отправить СМС с кодом"></input><br>
<input type="text" name="phone_code" placeholder="Введите код из СМС" class="form-control phone_input"><br>
<input onclick="send_form()" id="go_phone" type="button" name="submit" class="btn btn-success phone_bt" value="Подтвердить" disabled></input>
</div>
</div>
</form>
function send_form() {
$("#formx").submit();
}
function call() {
var msg = $('#formx').serialize();
$( "#phone_require" ).prop( "disabled", true );
$( "#formx" ).prop( "Подтвердить" );
$.ajax({
type: 'POST',
url: '/phone_require',
data: msg,
success: function(data) {
console.log(data);
$("form[name='submissions']").attr('onsubmit', 'call_code()');
$("input[name='submit']").attr('value', 'Подтвердить');
alert('Код был отправлен на ваш телефон.');
},
error: function(xhr, str){
console.log('Возникла ошибка: ' + xhr.responseCode);
}
});
}
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 60px;
margin-top: 0px;
}
</style>
</head>
<body>
<p id="demo"></p>
<script>
function countDown(elm, duration, fn){
// Set the date we're counting down to
var countDownDate = new Date().getTime() + (1000 * duration);
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
elm.innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
fn();
elm.innerHTML = "EXPIRED";
}
}, 1000);
}
countDown(document.getElementById('demo'), 5, function(){
alert('EXPIRED');
})
</script>
</body>
</html>
$_SESSSION['checkNowSms'] = time() + 120;
$checkNowSms = $_SESSION['checkNowSms'] ?? 0;
$distance = $checkNowSms - time();
if($distance <= 0) {
// показывам форму для ввода номера
} else {
// показывам форму для ввода смс кода.
}