I think the question is very easy for the knowledgeable. But as an unknowing php, I can't guess.
The site has several standard forms. Letters from these forms should be different in order to understand from which form the data came. I always did a separate php for each form, which is sure wrong).
How to use one php on all forms? Specify the name of input: submit and process if through?
Php code:
$email = $_POST['email']; $tel = $_POST['tel']; $email = $_POST['email']; $to = ''; $mail_message = ' <html> <head> <title>Заявка</title> </head> <body> <h2>Заявка с формы "Перезвоните мне"</h2> <ul> <li>E-mail: ' .$email. '</li> <li>Телефон: ' .$tel. '</li> </ul> </body> </html>'; $headers = 'From: ' . "\r\n" . 'Reply-To: ' . "\r\n" . "MIME-Version: 1.0" . "\r\n" . "Content-type: text/html; charset=UTF-8" . "\r\n"; $mail = mail($to, 'Заказ', $mail_message, $headers); Forms of this type:
<form action="" method="POST" class="calculate-form"> <input type="tel" name="tel" id="" placeholder="Ваш телефон" class="input calculate-input calculate-input--phone" required=""> <input type="text" name="text" id="" placeholder="сколько м2 ?" class="input calculate-input calculate-input--area" required=""> <input type="submit" value="Отправить" class="btn calculate-btn"> </form> Handler:
jQuery('.calculate-form').submit(function(e) { var $form = jQuery(this); jQuery.ajax({ type: $form.attr('method'), url: $form.attr('action'), data: $form.serialize() }).done(function() { successWindow.addClass("popup-success__wrapper--active"); $form[0].reset(); console.log('success'); }).fail(function() { console.log('fail'); }); //отмена действия по умолчанию для кнопки submit e.preventDefault(); });
inputwith the form type, and in the script handler, set the switch that determines which handler to use. - Rootware