Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://www.gravityhelp.com/forums/topic/explicitly-set-default-radio-choice-using-hook
- // change 29 here to your form ID
- add_filter('gform_pre_render_29', 'set_default_dynamically');
- function set_default_dynamically($form) {
- foreach( $form['fields'] as &$field ){
- // change 2 here to your field ID
- if( $field['id'] == 2 ){
- foreach($field['choices'] as &$choice) {
- // I want to set the radio button choice with the value of 31 to selected
- if($choice['value'] == '31'){
- $choice['isSelected'] = true;
- }
- // unset any default which was set in the form builder
- else {
- $choice['isSelected'] = '';
- }
- }
- }
- }
- // return the modified $form object
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement