Your full form code does contain a hidden input named action
with the value send_form
.
However, you’re not sending it correctly, because of the the contentType
part in your JS script, which submits the form data as a JSON payload, but note that the old admin-ajax.php
endpoint doesn’t support JSON payload, hence $_REQUEST['action']
would be empty unless if you added it to the URL query string, and therefore WordPress won’t know what the AJAX action is. So just remove the following from your JS code and the error would be gone:
contentType : 'application/json; charset=utf-8', // remove this
Additionally, your form doesn’t have an input named send_form
, so in your send_form()
function, this will fail: if (isset($_POST['send_form']))
. So you should add the input to your form or change the if
condition.
Also, you should call wp_die()
at the end in your function to exit the page and prevent WordPress from printing a 0
(zero).