Advertisement
HarunRRayhan

Gravity Forms execute Shortcode of Fields Text

Aug 2nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. add_filter( 'gform_pre_render', 'hrx_populate_choices' );
  2. add_filter( 'gform_pre_validation', 'hrx_populate_choices' );
  3. add_filter( 'gform_pre_submission_filter', 'hrx_populate_choices' );
  4. function hrx_populate_choices( $form ) {
  5.     //only populating drop down for form id 5
  6.     if ( $form['id'] != 5 ) {
  7.        return $form;
  8.     }
  9.  
  10.  
  11.    
  12.     // Get All Fields of the form
  13.     foreach ( $form['fields'] as &$field ) {
  14.  
  15.         // Debug Form Fields on HTML Field
  16.         if($field->id == 33){
  17.             $field->content = '<pre>' . print_r($form['fields'], true) . '</pre>';
  18.         }
  19.  
  20.  
  21.         // Auto-Populate Date field
  22.         if( $field->id == 32 && $field->type == 'select'  ){
  23.  
  24.             $previous_choices = $field->choices;
  25.  
  26.             $input_id = 1;
  27.             foreach ($previous_choices as $prev_chioce) {
  28.  
  29.                 //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
  30.                 if ( $input_id % 10 == 0 ) {
  31.                     $input_id++;
  32.                 }
  33.  
  34.                 $all_dates[] = array( 'text' => do_shortcode( $prev_chioce['text'] ), 'value' => $prev_chioce['value'] );
  35.  
  36.                 $input_id++;
  37.             }
  38.  
  39.    //       $time_one = do_shortcode('[pagedate index=2]') . ' at 7PM (' . do_shortcode('[geoip_detect2 property="location.timeZone"]') . ')';
  40.  
  41.    //       $all_dates[] = array(
  42.             //  'text' => $time_one,
  43.             //  'value' => "Time X"
  44.             // );
  45.  
  46.    //       $time_two = do_shortcode('[pagedate index=3]') . ' at 1PM (' . do_shortcode('[geoip_detect2 property="location.timeZone"]') . ')';
  47.  
  48.    //       $all_dates[] = array(
  49.             //  'text' => $time_two,
  50.             //  'value' => "Time Y"
  51.             // );
  52.  
  53.             // $time_three = do_shortcode('[pagedate index=4]') . ' at 11AM (' . do_shortcode('[geoip_detect2 property="location.timeZone"]') . ')';
  54.  
  55.    //       $all_dates[] = array(
  56.             //  'text' => $time_three,
  57.             //  'value' => "Time Z"
  58.             // );
  59.  
  60.             // Placeholded for auto populate date
  61.             // $field->placeholder = 'Select a Date';
  62.             $field->choices = $all_dates;
  63.  
  64.         }
  65.  
  66.     }
  67.     return $form;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement