Advertisement
mjdigital

Gravity Forms Dynamic Checkbox Prices

Mar 12th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. //Adds a filter to forms
  2. add_filter("gform_pre_render", add_dynamic_options);
  3. //add_filter("gform_admin_pre_render", add_dynamic_options); // Run code in the admin section (not needed)
  4.  
  5. function add_dynamic_options($form){   
  6.     foreach($form["fields"] as &$field){
  7.         // replace prices on fields with dynamic_options class
  8.         if($field["cssClass"] == 'dynamic_options'){
  9.              foreach($field['choices'] as $chID => $choice) {
  10.                 // get the value
  11.                 $dynVal     = $choice['value'];
  12.                 $realVal    = @$_GET[$dynVal]; // actual value can be retrieved from wherever but I use $_GET variables
  13.                 if($realVal!='') {
  14.                     $field['choices'][$chID]['value'] = $field['choices'][$chID]['text']; // Set value as the Title - makes it easier to understand later
  15.                     $field['choices'][$chID]['price'] = $realVal;
  16.                 }
  17.             }
  18.         }
  19.     }
  20.     return $form;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement