GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
search-field-select.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Display the search SELECT input field
4  *
5  * @file class-search-widget.php See for usage
6  */
7 
9 $view_id = $gravityview_view->getViewId();
11 
12 // Make sure that there are choices to display
13 if( empty( $search_field['choices'] ) ) {
14  gravityview()->log->debug( 'search-field-select.php - No choices for field' );
15  return;
16 }
17 
18 if( is_array( $search_field['value'] ) ) {
19  gravityview()->log->debug( 'search-field-select.php - Array values passed; using first value.' );
20  $search_field['value'] = reset( $search_field['value'] );
21 }
22 
23 $gf_field = GFAPI::get_field( $gravityview_view->getForm(), $search_field['key'] );
24 $placeholder = \GV\Utils::get( $gf_field, 'placeholder', '' );
25 
26 /**
27  * @filter `gravityview/extension/search/select_default` Define the text for the default option in a select (multi or single dropdown)
28  * @since 1.16.4
29  * @param string $default_option Default: `&mdash;` (—)
30  * @param string $field_type Field type: "select" or "multiselect"
31  */
32 $default_option = apply_filters('gravityview/extension/search/select_default', ( '' === $placeholder ? '&mdash;' : $placeholder ), 'select' );
33 
34 ?>
35 <div class="gv-search-box gv-search-field-select">
36  <?php if( ! gv_empty( $search_field['label'], false, false ) ) { ?>
37  <label for="search-box-<?php echo esc_attr( $search_field['name'] ); ?>"><?php echo esc_html( $search_field['label'] ); ?></label>
38  <?php } ?>
39  <p>
40  <select name="<?php echo esc_attr( $search_field['name'] ); ?>" id="search-box-<?php echo esc_attr( $search_field['name'] ); ?>">
41  <option value="" <?php gv_selected( '', $search_field['value'], true ); ?>><?php echo esc_html( $default_option ); ?></option>
42  <?php
43  foreach( $search_field['choices'] as $choice ) { ?>
44  <?php if ( is_array( $choice['value'] ) ) { ?>
45  <optgroup label="<?php echo esc_attr( $choice['text'] ); ?>">
46  <?php foreach ( $choice['value'] as $subchoice ): ?>
47  <option value="<?php echo esc_attr( $subchoice['value'] ); ?>"><?php echo esc_html( $subchoice['text'] ); ?></option>
48  <?php endforeach; ?>
49  </optgroup>
50  <?php } else { ?>
51  <option value="<?php echo esc_attr( $choice['value'] ); ?>" <?php gv_selected( esc_attr( $choice['value'] ), esc_attr( $search_field['value'] ), true ); ?>><?php echo esc_html( $choice['text'] ); ?></option>
52  <?php } ?>
53  <?php } ?>
54  </select>
55  </p>
56 </div>
static getInstance( $passed_post=NULL)
if(empty( $search_field['choices'])) if(is_array( $search_field['value'])) $gf_field
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
gv_empty( $value, $zero_is_empty=true, $allow_string_booleans=true)
Is the value empty?
gv_selected( $value, $current, $echo=true, $type='selected')
Similar to the WordPress selected(), checked(), and disabled() functions, except it allows arrays to ...
$gravityview_view