SHARE
TWEET

Gravity Forms Dynamic Checkbox Prices

mjdigital Mar 12th, 2013 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top