Answer the question
In order to leave comments, you need to log in
php ajax js feedback form. How to receive data on the server?
There is a form:
<form form-name="callback" id='callback' class="js-form">
<div class="form-group">
<input field-name="phone" name="phone" type="text" class="phone form-control" placeholder="+7 (___) ___-__-__">
<small class="form-text text-muted">Укажите ваш номер телефона и мы свяжемся с вами в ближайшее время.</small>
</div>
<button class="submit btn btn-warning">Перезвоните мне!</button>
</form>
self.Send = function()
{
if ( typeof self.GetExport().phone !== 'undefined' )
{
var obj = JSON.stringify( self.GetExport() );
console.log( obj );
$.post( 'no', obj )
.done( function( data )
{
console.log( data );
self.Clear();
modals.HideAll(); // скрыть все модальные окна
modals.Open( 'form-success' ); // показать modal success
} );
}
else
{
alert( 'Номер телефона не может быть пустым!' );
}
};
<?php
if (isset($_POST['email'])) {$email = $_POST['email']; if ($email == '') {unset($email);}}
if (isset($_POST['phone'])) {$phone = $_POST['phone']; if ($phone == '') {unset($phone);}}
if (isset($_POST['name'])) {$text = $_POST['name']; if ($text == '') {unset($text);}}
$answer=['ok'=>$phone.' = phone'];
if (isset($email) or isset($phone) or isset($text)){
$to = "<[email protected]***.ru>, " ;
$to .= "<***[email protected]>";
$subject = "Заявка с сайта!";
$message = ' <b>Имя:'.$name.' </b> </br> <b>Телефон: '.$phone.'</b> </br><i>Почта: '.$email.'</i> </br>';
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: <[email protected]***>\r\n";
$headers .= "Reply-To: ***[email protected]\r\n";
$send = mail($to, $subject, $message, $headers);
if ($send == true) {
$answer =[
'ok'=>'done'
];
}
else {
$answer=[
'ok'=>'error'
];
}
}
echo json_encode($answer);
?>
Answer the question
In order to leave comments, you need to log in
Start by checking the php script input. Dump $_POST (and $_GET) with var_dump or var_export
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question