Answer the question
In order to leave comments, you need to log in
{Wordpress} After submitting the form, how do I create a post based on the filled in data?
Here is the form submission code. It is called by ajax.
<?php
$to = '[email protected]'; адресов
$subject = 'Заголовок';
$message = '
<html>
<head>
<title>' . $subject . '</title>
</head>
<body>
<p>Имя: ' . $_POST['invoice-name'] . '<br />
Геолокация: ' . $_POST['invoice-city'] . '<br />
Программа интересует: ' . $_POST['invoice-msg'] . '<br />
Телефон: ' . $_POST['invoice-tel'] . '<br />
Эл. почта: ' . $_POST['invoice-email'] . '</p>
</body>
</html>';
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: JoyFans <[email protected]> \r\n";
mail($to, $subject, $message, $headers);
return 200;
?>
Answer the question
In order to leave comments, you need to log in
First, why are you writing a completely custom send when WordPress has wp_mail()?
The scheme is as follows:
1. You must send the form to admin-ajax.php using Ajax (google ajax in WordPress)
2. You must have your own callback / handler on the wp_ajax_{action} and wp_ajax_nopriv_{action} hooks
3. Validate the data in the handler ( you can't just disable $_POST['var'] without validation)
4. After validation, send a letter using wp_mail()
5. And create a new post using wp_insert_post()
6. After creating a post, you have its ID, add the necessary metadata via API ACF
7. Return what you need to the browser
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question