Create the Drop Box
There is already a function that creates the search box, so this function overloads the parent function in order to create HTML code to display the drop box, then it calls the parent search box function to display the standard search box HTML code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | function search_box( $text, $input_id ) { /* * If there are no items in the table, then do not display the search box */ if ( ( ! $this->has_items() ) ) { return; } /* * If the function that returns the searchable columns exists and * if it is returns a filled array of columns, * then display the drop box */ if ( method_exists( $this, ‘get_searchable_columns’ ) && ( array() !== $this->get_searchable_columns() ) ) { echo( ‘<p class=“search-box”>’ ); echo( ‘<select multiple=“multiple” name=“sc” size=“1” >’ ); /* * Option “ALL” listed first, selects every searchable column */ echo( ‘<option value=“ ‘ ); foreach ( array_keys( $this->get_searchable_columns() ) as $key ) { echo( $key . ‘,’ ); } echo( ’ ” ’ ); if ( ! isset( $_REQUEST[ ‘sc’ ] ) ) { echo( ‘selected ’ ); // Also defaults here when selected and nothing else was selected } echo( ‘/>All’ ); /* * Specify individual options */ foreach ( $this->get_searchable_columns() as $key => $name ) { echo( ‘<option value=“ ‘ . $key . ’ ” ’ ); if ( ( isset( $_REQUEST[ ‘sc’ ] ) ) && ( $key === $_REQUEST[ ‘sc’ ] ) ) { echo( ‘selected ’ ); } echo( ‘/>’ . $name ); } echo( ‘</select>’ ); echo( ‘</p>’ ); } /* * Otherwise select all keys based on the overall columns * These keys are selected through a hidden parameter */ else { echo( ‘<input type=“hidden” name=“sc” value=“ ‘ ); foreach ( array_keys( $this->get_columns() ) as $key ) { if ( ‘cb’ !== $key ) { echo( $key . ‘,’ ); } } echo( ’ ” />’ ); } /* * Call the parent routine to complete setting up the search box */ parent::search_box( $text, $input_id ); } |
The actual code returned in this situation looks like this:
1 2 3 4 5 6 7 8 | <select name=“sc” size=“1” > <option value=“time,ip,reqUrl,platform,userAgent,” selected />All <option value=“time” />Date / Time (GMT) <option value=“ip” />IP Address <option value=“reqUrl” />Requested URL <option value=“platform” />Platform <option value=“userAgent” />User Agent </select> |
As this function overrides the parent function, there is no need to change the actual calling statement.
The short URL of the present article is: http://www.terryobrien.me/Oodqa
Personal Links