Advertisement
w0lfiesmith

AJAX handler demo, add to functions.php

Feb 9th, 2012
6,269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement