Advertisement
redearth

Gravity Forms coupon code - wp ajax

May 17th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. function ajax_getchoices_fromfield() {
  2.     global $wpdb;
  3.     $form_id = false;
  4.  
  5.     if(strip_tags($_POST['adminLabel'])){
  6.         $adminLabel = strip_tags($_POST['adminLabel']);
  7.     }
  8.     if(intval($_POST['form_id'])){
  9.         $form_id = intval($_POST['form_id']);
  10.     }
  11.  
  12.     if(isset($adminLabel) && $form_id > 0){
  13.         $choices = array();
  14.         // get the choices from a hidden admin-only field
  15.         //$result = $wpdb->get_row("SELECT display_meta FROM med_rg_form_meta WHERE form_id = ".(int)$form_id, ARRAY_A);
  16.         //$display_meta = unserialize($result['display_meta']);
  17.         $display_meta = GFAPI::get_form($form_id);// switched to use the GF API
  18.  
  19.         if(!empty($display_meta['fields'])){
  20.             foreach($display_meta['fields'] as $key=>$field){
  21.                 // pull out just the hidden admin-only coupon codes, or whichever adminlabel
  22.                 if($field['adminOnly']==1 && $field['adminLabel']==$adminLabel){
  23.                     $choices = $field['choices'];
  24.                 }
  25.             }
  26.         }
  27.         if(!empty($choices)){
  28.             echo json_encode($choices);
  29.         }
  30.     }
  31.     exit;
  32. }
  33. add_action('wp_ajax_getchoices_fromfield', 'ajax_getchoices_fromfield');
  34. add_action('wp_ajax_nopriv_getchoices_fromfield', 'ajax_getchoices_fromfield');//for users that are not logged in.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement