Sending data with multi step form to wp database

Question

I have a multi step form and I need to save data from each step to the db. First step is contact details and by clicking button “Next” data should be saved to db.

In my form template I have js code for collecting and sanding data to php file

function Send_Data_Post_In() {
            var name = document.getElementById("first_name").value;
            var lastname = document.getElementById("last_name").value;
            var email = document.getElementById("user_email").value;
            var phone = document.getElementById("phone").value;

            var httpr = new XMLHttpRequest();
            httpr.open("POST", "/post-expance.php", true);
            httpr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

            httpr.send("&name=" + name + "&lastname=" + lastname + "$email" + email + "$phone" + phone);
            console.log(httpr);

        }

And php file is

include_once '/wp-config.php';

$name = $_POST['first_name'];
$lastname = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$sql = "INSERT INTO step_form (first_name, last_name, email, phone) VALUES ('$name', '$lastname', '$email', '$phone');";

$result = mysqli_query($wpdb, $sql);
0
, Stasonn L 4 years 2019-12-02T08:19:45-05:00 0 Answers 59 views 0

Leave an answer

Browse
Browse