Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active August 8, 2021 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/78118094c4a1f324485c567af3a59466 to your computer and use it in GitHub Desktop.
Save xnau/78118094c4a1f324485c567af3a59466 to your computer and use it in GitHub Desktop.
Shows how to set up a dropdown search input for a Participants Database list display.
<?php
/*
template for participants list shortcode output
this template demonstrates a "table-less" responsive layout for the list of records
with a dropdown selector search interface
*/
/**
* provides an array of dropdown values
* @param string $name of the field
* @return array
*/
if ( ! function_exists( 'pdb_dropdown_values' ) ) {
function pdb_dropdown_values($name) {
$field = Participants_Db::$fields[$name];
if ($field) {
$values = $field->options();
}
if (is_array($values)) {
return $values;
} else {
return array('');
}
}
}
?>
<div class="wrap <?php echo $this->wrap_class ?>" id="<?php echo $this->list_anchor ?>">
<?php /* SEARCH/SORT FORM */ ?>
<?php if ( $filter_mode != 'none' ) : ?>
<div class="pdb-searchform">
<div class="alert alert-block" style="display:none">
<a class="close" data-dismiss="alert" href="#">X</a>
<p class="search_field_error"><?php _e( 'Please select a column to search in.', 'participants-database' )?></p>
<p class="value_error"><?php _e( 'Please type in something to search for.', 'participants-database' )?></p>
</div>
<?php $this->search_sort_form_top( false, 'form-horizontal' ); ?>
<?php if ( $filter_mode == 'filter' || $filter_mode == 'both' ) : ?>
<div class="control-group">
<label class="control-label"><?php _e('Search', 'participants-database' )?>:</label>
<div class="controls">
<!-- this selectd the field to search on -->
<input type="hidden" name="search_field" value="interests" class="search-item" />
<!-- this provides the search operator -->
<input name="operator" type="hidden" class="search-item" value="LIKE" />
<?php
PDb_FormElement::print_element(
array(
'type' => 'dropdown',
'name' => 'value',
'options' => pdb_dropdown_values('interests'),
'class' => 'search-item',
'value' => filter_input(INPUT_POST, 'value', FILTER_SANITIZE_STRING)
)
);
?>
<?php echo $this->search_submit_buttons(); ?>
</div>
</div>
<?php endif ?>
<?php if ( $filter_mode == 'sort' || $filter_mode == 'both' ) : ?>
<div class="control-group">
<label class="control-label"><?php _e('Sort by', 'participants-database' )?>:</label>
<div class="controls">
<?php $this->sort_form() ?>
</div>
</div>
<?php endif ?>
</div>
<?php endif ?>
<?php // this is an example of a way to style the records, delete this or edit as needed ?>
<style type="text/css">
section {
margin: 1.5em 0;
}
.pdb-field-title {
font-weight: bold;
padding-right: 15px;
}
.pdb-field-title:after {
content: ':';
}
</style>
<div class="pdb-list list-container" >
<?php
/* print the count if enabled in the shortcode
*
* the tag wrapping the count statment can be supplied in the function argument, example here
*/
$this->print_list_count('<h5>');
?>
<?php if ( $record_count > 0 ) : ?>
<?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?>
<section id="record-<?php echo $this->record->record_id ?>">
<?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?>
<?php if ( $this->field->has_content() ) : ?>
<div class="pdb-field">
<span class="pdb-field-title"><?php echo $this->field->title ?></span>
<span class="pdb-field-data"><?php echo PDb_FormElement::get_field_value_display($this->field); ?></span>
</div>
<?php else : // if the field is empty ?>
<?php endif ?>
<?php endwhile; // each field ?>
</section>
<?php endwhile; // each record ?>
<?php else : // if there are no records ?>
<h4><?php if ($this->is_search_result === true) echo Participants_Db::$plugin_options['no_records_message'] ?></h4>
<?php endif; // $record_count > 0 ?>
</div>
<?php
// set up the bootstrap pagination classes and wrappers
// set up the bootstrap-style pagination block
// sets the indicator class for the pagination display
$this->pagination->set_current_page_class( 'active' );
// wrap the current page indicator with a dummy anchor
$this->pagination->set_anchor_wrap( false );
$this->pagination->set_props(array(
'first_last' => false,
'current_page_class'=>'active currentpage',
'wrappers' => array(
'wrap_class' => 'pagination-large pagination-centered',
'list_class' => '',
),
));
$this->pagination->show();
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment