Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Adds a filter to forms
- add_filter("gform_pre_render", add_dynamic_options);
- //add_filter("gform_admin_pre_render", add_dynamic_options); // Run code in the admin section (not needed)
- function add_dynamic_options($form){
- foreach($form["fields"] as &$field){
- // replace prices on fields with dynamic_options class
- if($field["cssClass"] == 'dynamic_options'){
- foreach($field['choices'] as $chID => $choice) {
- // get the value
- $dynVal = $choice['value'];
- $realVal = @$_GET[$dynVal]; // actual value can be retrieved from wherever but I use $_GET variables
- if($realVal!='') {
- $field['choices'][$chID]['value'] = $field['choices'][$chID]['text']; // Set value as the Title - makes it easier to understand later
- $field['choices'][$chID]['price'] = $realVal;
- }
- }
- }
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement