SHARE
TWEET

AJAX handler demo, add to functions.php

w0lfiesmith Feb 9th, 2012 5,259 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. wp_enqueue_script('jquery');
  2.  
  3. function addCustomer(){
  4.        
  5.         global $wpdb;
  6.        
  7.         $name = $_POST['name'];
  8.         $phone = $_POST['phone'];
  9.         $email = $_POST['email'];
  10.         $address = $_POST['address'];
  11.        
  12.         if($wpdb->insert('customers',array(
  13.                 'name'=>$name,
  14.                 'email'=>$email,
  15.                 'address'=>$address,
  16.                 'phone'=>$phone
  17.                 ))===FALSE){
  18.        
  19.                 echo "Error";
  20.                
  21.         }
  22.         else {
  23.                         echo "Customer '".$name. "' successfully added, row ID is ".$wpdb->insert_id;
  24.  
  25.                 }
  26.         die(); 
  27. }
  28. add_action('wp_ajax_addCustomer', 'addCustomer');
  29. add_action('wp_ajax_nopriv_addCustomer', 'addCustomer');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top