In laravel Blade code, I want to get mobile number from the input field in a js variable.then I want to directly send the otp in that number while pressed in "continue" button without loading or refreshing the page. I stored the number in a js variable and my otp sending code in a php code.How can i use the js variable in the php? here is my code:
<script type="text/javascript">
$("#submitForm").click(function(){
$("#mobile_number_login").fadeOut(250);
var number = $('input[name="phone_number"]').val();
@php
function random_otp( $length = 4 ) {
$chars = "0123456789";
$otpcreate = substr(str_shuffle($chars),0,$length);
return $otpcreate;
}
$otp = random_otp(4);
$sms = DB::table('sms_template')
->join('sms_settings','sms_template.sms_settings_id','=','sms_settings.id')
->where('sms_template.id',18)
->FIRST();
$n1 = str_replace('[[OTP]]',$otp,$sms->message);
$encoded_message = urlencode($n1);
// create a new cURL resource
$ch = curl_init();
$m1 = str_replace('[[sms]]',"$encoded_message",$sms->link);
$api = str_replace('[[gsm]]','+number+',$m1);
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
@endphp
});
</script>
in api variable i want to use number variable to send the otp.is it possible? here is my html part:
<input type="text" class="form-control" name="phone_number" placeholder="01**********>
<a id="submitForm" style="background-color: #a5abb0;" class="mobile-login__button">CONTINUE
</a>