Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <?php
  2. $address_line_1 = $_POST['address_line_1'];
  3. $address_line_2 = $_POST['address_line_2'];
  4. $suburb = $_POST['suburb'];
  5. $state = $_POST['state'];
  6. $post_code = $_POST['post_code'];
  7. $country = $_POST['country'];
  8. $email = $_POST['email'];
  9. $first_name = $_POST['first_name'];
  10. $last_name = $_POST['last_name'];
  11. $phone_number = $_POST['phone_number'];
  12. $progress_identifier = '1';
  13.  
  14. // PROCESS THE FORM
  15. if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == "new_customer")
  16. {
  17.  
  18. $new_customer = array(
  19. 'post_title' => wp_rand(100,999).'-'.wp_rand(),
  20. 'post_author' => $user_ID,
  21. 'post_status' => 'publish',
  22. 'post_type' => 'customer'
  23. );
  24.  
  25. $pid = wp_insert_post($new_customer);
  26.  
  27. add_post_meta($pid, 'address_line_1', $address_line_1, true);
  28. add_post_meta($pid, 'address_line_2', $address_line_2, true);
  29. add_post_meta($pid, 'suburb', $suburb, true);
  30. add_post_meta($pid, 'state', $state, true);
  31. add_post_meta($pid, 'post_code', $post_code, true);
  32. add_post_meta($pid, 'country', $country, true);
  33. add_post_meta($pid, 'email', $email, true);
  34. add_post_meta($pid, 'first_name', $first_name, true);
  35. add_post_meta($pid, 'last_name', $last_name, true);
  36. add_post_meta($pid, 'phone_number', $phone_number, true);
  37. add_post_meta($pid, 'address', $address, true);
  38. add_post_meta($pid, 'progress_identifier', $progress_identifier, true);
  39.  
  40. $survey_post = array(
  41. 'post_title' => $pid . '-' . wp_rand(),
  42. 'post_author' => $user_ID,
  43. 'post_status' => 'publish',
  44. 'post_type' => 'survey'
  45. );
  46.  
  47. $survey_id = wp_insert_post($survey_post);
  48.  
  49. global $wpdb;
  50. $wpdb->insert(
  51. $wpdb->p2p,
  52. array(
  53. 'p2p_from' => $survey_id,
  54. 'p2p_to' => $pid,
  55. 'p2p_type' => 'survey_to_customer'
  56. )
  57. );
  58. wp_redirect(home_url());
  59. exit();
  60. }
  61. ?>
  62.  
  63. exit;
  64.  
  65. function my_function_to_hendle_ajax() {
  66. $address_line_1 = $_POST['address_line_1'];
  67. $address_line_2 = $_POST['address_line_2'];
  68. $suburb = $_POST['suburb'];
  69. $state = $_POST['state'];
  70. //....
  71. // no need in if( 'post' .... )
  72. $new_customer = array(
  73. 'post_title' => wp_rand(100,999).'-'.wp_rand(),
  74. 'post_author' => $user_ID,
  75. 'post_status' => 'publish',
  76. 'post_type' => 'customer'
  77. );
  78.  
  79. $pid = wp_insert_post($new_customer);
  80.  
  81. add_post_meta($pid, 'address_line_1', $address_line_1, true);
  82. add_post_meta($pid, 'address_line_2', $address_line_2, true);
  83. // ....
  84. wp_redirect(home_url());
  85. exit();
  86. }
  87.  
  88. <form action="<?php echo admin_url( 'admin-ajax.php' ); ?>" method="POST">
  89. <input type="hidden" name="action" value="new_customer" />
  90. ...
  91. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement