Advertisement
Guest User

Code

a guest
Sep 17th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. add_filter('gform_pre_render_7', 'gform_populate_selected_options');
  2. add_filter('gform_pre_submission_filter_7', 'gform_populate_selected_options');
  3. function gform_populate_selected_options($form) {
  4.    
  5.     $field_id = 8; // update to the ID of your options field
  6.     $option_price = '305.00'; // update to the price of your options
  7.     $no_options_message = 'We\'re sorry, there were no options specified.'; // message displayed when no options were selected
  8.    
  9.     /* you should not need to edit below this line */
  10.    
  11.     foreach($form['fields'] as &$field) {
  12.        
  13.         if($field['id'] != $field_id)
  14.             continue;
  15.    
  16.         $selected_options = explode(',', rgget($field['inputName']));
  17.         $choices = array();
  18.         $inputs = array();
  19.        
  20.         if(!rgget($field['inputName'])) {
  21.            
  22.             $field['description'] = $no_options_message;
  23.            
  24.         } else {
  25.            
  26.             $input_id = 1;
  27.             foreach($selected_options as $selected_option) {
  28.                
  29.                 $choices[] = array('text' => $selected_option, 'value' => $selected_option, 'price' => '305.00', 'isSelected' => true);
  30.                
  31.                 if($input_id % 10 == 0)
  32.                     $input_id++;
  33.                
  34.                 $inputs[] = array('id' => "{$field['id']}.{$input_id}", 'label' => $selected_option, 'name' => '');
  35.                 $input_id++;
  36.                
  37.             }    
  38.            
  39.         }
  40.        
  41.         $field['choices'] = $choices;
  42.         $field['inputs'] = $inputs;
  43.         $field['enableChoiceValue'] = false;
  44.        
  45.     }
  46.    
  47.     return $form;}
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement