Нужно чтобы при нажатии на кнопку в телеграмм отправлялась форма, она отправляется, но выводит пустое значение в поле имя и телефон.
<?php
$name = $_POST['user_name'];
$phone= $_POST['user_phone'];
$email= $_POST['user_email'];
$token= "95690M";
$chat_id = "-378235328";
$arr = array(
'Имя пользователя:'=>$name,
'Телефон:'=>$phone,
'Email:'=>$email
);
foreach ($arr as $key => $value) {
$txt .="<b>".$key."</b>".$value."%0A";
}
$sendToTelegramm = fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
?>
function ajaxPost(params){
var request = new XMLHttpRequest();
request.open('POST', '<?php echo get_template_directory_uri()?>/telegramm.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.send(params);
}
checkout.addEventListener('click', check);
function check(){
if(checkoutName.value == "" || checkoutPhone.value == ""){
checkoutBG.style = 'opacity:1.08; display:block;';
alertFall.classList.remove('hideSweetAlert');
alertFall.classList.add('showSweetAlert');
alertFall.classList.add('visible');
alertFall.style ='display:block;margin-top:-179px;';
}else{
ajaxPost();
checkoutBG.style = 'opacity:1.08; display:block;';
alertAccess.classList.remove('hideSweetAlert');
alertAccess.classList.add('showSweetAlert');
alertAccess.classList.add('visible');
alertAccess.style ='display:block;margin-top:-179px;';
}
}
<form method="POST" class="form text-in" id="form0">
<div class="fields">
<div class="field" style="width: 177px;">
<div class="input">
<input id="checkoutName" name="user_name" class="form-control text" type="text" placeholder="Имя *" value="" style="border-radius: 0px;">
</div>
</div>
<div class="field" data-type="phone" style="width: 177px;">
<div class="input">
<input id="checkoutPhone" name="user_phone" class="form-control text" type="text" placeholder="Телефон *" value="" style="border-radius: 0px;">
</div>
</div>
</div>
<div class="macros-button">
<div class="btn-out full xs-none">
<div class="btn-inner">
<button class="btn font-text submit" id="uid19" type="button">
<span class="text">Оформить заказ</span>
</button>
</div>
</div>
</div>
</form>
Код может написан кривовато, но это всё потому что я новичок)