Call to undefined add_action() in theme’s functions.php

register an ajax action for submitting email:

Note handle_form is the name of your action in this example

add_action('wp_ajax_handle_form','handle_form_submit_111605' );

also add this in order to make it work for non logged in users

add_action('wp_ajax_nopriv_handle_form','handle_form_submit_111605' );

do validation and mail sending job in the callback function handle_form_submit_111605

In functions.php

function handle_form_submit_111605() {

}

User simply jquey ajax to submit the form through ajax
In you js file

<script type="text/jaascript">

var submitdata =  myForm.serialize();
jQuery.ajax({
  url: 'http://domain/wp-admin/admin-ajax.php?action=handle_form',
      //action parameter is the same one you used while registering the ajax
  type: 'POST',
  data: submitData,
  success: function(data, textStatus, xhr) {
     if(data.status){
         // ...
     }
   }
 });
</script>

See more here

Leave a Comment