Skip to content

Instantly share code, notes, and snippets.



Last active Oct 6, 2020
What would you like to do?
Shows how to set up a Participants Database signup form that limits the number of signups
* signup form that limits the number of signups
// set the maximum number of signups
$limit = 100;
// set up the query to get the current total
$query = 'SELECT COUNT(*) FROM ' . Participants_Db::$participants_table;
// get the total
global $wpdb;
$total = $wpdb->get_var( $query );
<div class="wrap <?php echo $this->wrap_class ?>" >
<?php if ( $total > $limit ) : // show this if the limit has been reached ?>
<p>There are no more signups available</p>
<?php else : // print the signup form ?>
<?php // output any validation errors
$this->print_errors(); ?>
<?php $this->print_form_head(); // this must be included before any fields are output. hidden fields may be added here as an array argument to the function ?>
<table class="form-table pdb-signup">
<?php while ( $this->have_groups() ) : $this->the_group(); ?>
<tbody class="field-group field-group-<?php echo $this->group->name ?>">
<?php if ( $this->group->has_fields() && $this->group->printing_title() ) : // are we printing group titles and descriptions? ?>
<tr class="signup-group">
<td colspan="2">
<?php $this->group->print_title() ?>
<?php $this->group->print_description() ?>
<?php else : ?>
<?php endif; // end group title/description row ?>
<?php while ( $this->have_fields() ) : $this->the_field(); ?>
<tr class="<?php $this->field->print_element_class() ?>">
<th for="<?php $this->field->print_element_id() ?>"><?php $this->field->print_label(); // this function adds the required marker ?></th>
<?php $this->field->print_element_with_id(); ?>
<?php if ( $this->field->has_help_text() ) :?>
<span class="helptext"><?php $this->field->print_help_text() ?></span>
<?php endif ?>
<?php endwhile; // fields ?>
<?php endwhile; // groups ?>
<tbody class="field-group field-group-submit">
<td class="submit-buttons">
<?php $this->print_submit_button('button-primary'); // you can specify a class for the button ?>
<td class="submit-buttons">
<?php $this->print_retrieve_link(); // this only prints if enabled in the settings ?>
<?php $this->print_form_close() ?>
<?php endif ?>

This comment has been minimized.

Copy link
Owner Author

@xnau xnau commented Oct 6, 2020

If you don't want to to count all the records, you can change the query. For example, to only count the "approved" records, you can use a query like this:

'SELECT COUNT(*) FROM ' . Participants_Db::$participants_table . ' WHERE approved = "yes"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment