Skip to content

Instantly share code, notes, and snippets.

Last active September 24, 2022 17:38
What would you like to do?
Template for a Participants Database signup form that demonstrates how to disable or enable a field based on the selected value of another field
* template for the signup form
* shows an example of letting the selected value of a radio control enable or disable another field
jQuery(document).ready(function($){ // this waits until the page is loaded to initialize the function
// this is the field that controls the display of the text field
var radioField = $('[name=mailing_list]');
// this is the text field we are changing with the script
var textField = $('[name=email]');
// define the function that will change the state of the text field
var switchState = function(obj){
// check the obj argument, it will either be an element or an action
// if it is an action, get the target property
// this gives us the element that was clicked on
var field = obj.length ? obj : $(;
// this is the text field's container
var container = textField.closest('tr.text-line');
switch(field.filter(':checked').val()){ // get the value and act on it
case 'No':
textField.prop('disabled',true); // disables the email input
container.css({opacity:0.5}); // greys out the email input line
case 'Yes':
textField.prop('disabled',false); // enables the email input
container.css({opacity:1}); // un-greys out the email input line
// attach the function to the action
// set the initial state
<div class="wrap <?php echo $this->wrap_class ?>" >
<?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() ?>
Copy link

xnau commented Sep 23, 2022

Ths script in this template will undoubtedly need to be modified to work for the specific circumstances in your case, but it can provide a simple framework for this kind of interaction.

Read the documentation on how to set up and use Participants Database shortcode templates.

Once you have the template uploaded and modified for your purpose, use it with

[pdb_signup template=radioselect]

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