Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'gform_pre_render', 'hrx_populate_choices' );
- add_filter( 'gform_pre_validation', 'hrx_populate_choices' );
- add_filter( 'gform_pre_submission_filter', 'hrx_populate_choices' );
- function hrx_populate_choices( $form ) {
- //only populating drop down for form id 5
- if ( $form['id'] != 5 ) {
- return $form;
- }
- // Get All Fields of the form
- foreach ( $form['fields'] as &$field ) {
- // Debug Form Fields on HTML Field
- if($field->id == 33){
- $field->content = '<pre>' . print_r($form['fields'], true) . '</pre>';
- }
- // Auto-Populate Date field
- if( $field->id == 32 && $field->type == 'select' ){
- $previous_choices = $field->choices;
- $input_id = 1;
- foreach ($previous_choices as $prev_chioce) {
- //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
- if ( $input_id % 10 == 0 ) {
- $input_id++;
- }
- $all_dates[] = array( 'text' => do_shortcode( $prev_chioce['text'] ), 'value' => $prev_chioce['value'] );
- $input_id++;
- }
- // $time_one = do_shortcode('[pagedate index=2]') . ' at 7PM (' . do_shortcode('[geoip_detect2 property="location.timeZone"]') . ')';
- // $all_dates[] = array(
- // 'text' => $time_one,
- // 'value' => "Time X"
- // );
- // $time_two = do_shortcode('[pagedate index=3]') . ' at 1PM (' . do_shortcode('[geoip_detect2 property="location.timeZone"]') . ')';
- // $all_dates[] = array(
- // 'text' => $time_two,
- // 'value' => "Time Y"
- // );
- // $time_three = do_shortcode('[pagedate index=4]') . ' at 11AM (' . do_shortcode('[geoip_detect2 property="location.timeZone"]') . ')';
- // $all_dates[] = array(
- // 'text' => $time_three,
- // 'value' => "Time Z"
- // );
- // Placeholded for auto populate date
- // $field->placeholder = 'Select a Date';
- $field->choices = $all_dates;
- }
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement