How to make a feedback form php and ajax?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
28 views
Hello.
Want to make a feedback form, to -Name, -Surname, -Email, -Message

Code looks like this:
Send Message<!-- form -->
by | 28 views

1 Answer

0 like 0 dislike
To send data via Ajax you need to write the following JS code.

$(document).ready(function(){ $(".main_button").on("click", function(e){ var name = $("input[name='name']").val(); var lastname = $("input[name='lastname']").val(); var email = $("input[name='email']").val(); var message = $("#exampleFormControlTextarea1").val(); $.ajax({ type: "post", url: "/ajax/send", // ajax data otpravyat data: { firstname: name, lastname: lastname, email: email, message: message}, success: function(){ alert("Successfully submitted"); window.location = "/"; }, error: function(){ // if the error } }); }); });


Then you need to write the handler on the side of the back-end.

<?php\r/* в начале нужно тут написать соединение с вашей БД */\r\r$firstname = $_POST['firstname'];\r$lastname = $_POST['lastname'];\r$email = $_POST['email'];\r$message = $_POST['message'];\r\r/* Потом можно уже записать полученные данные из формы в БД */\r?>
by

Related questions

0 like 0 dislike
2 answers
asked May 1, 2019 by mlkis_0200
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Apr 4, 2019 by volkovecgenei
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users