Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active June 8, 2023 22:20
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/43d3585c1d46bc54ad2fbbb7fb0dca03 to your computer and use it in GitHub Desktop.
Save xnau/43d3585c1d46bc54ad2fbbb7fb0dca03 to your computer and use it in GitHub Desktop.
Demonstrates how to add fields to a Participants Database Contact Form
<?php
/**
* Plugin Name: PDB Contact Form Additions
* Description: adds additional fields to the Participants Database contact form
* Version: 2.1
*/
add_action( 'pdbcff-before_message_area', 'pdbcfa_add_fields' );
/**
* inserts additional fields into the contact form
*
*/
function pdbcfa_add_fields()
{
?>
<label for="pdbcff-phone">Phone Number</label>
<input type="tel" pattern="^\d{3}-\d{3}-\d{4}$" title="phone number format: 123-456-7890" name="pdbcff-phone" value="" required id="pdbcff-phone" />
<?php
}
/**
* this demonstrates the use of the pdbcff-form_item_definitions filter to change how the contact form is configured
*
* @param array $form_items
* @return array form items array
*/
function pdbcfa_modify_form_fields( $form_items )
{
// we are making the message body field not required
foreach( $form_items as $key => &$item )
{
if ( $item['name'] === 'body' )
{
$item['required'] = false;
// if you want to delete the item from the form use:
// unset( $form_items[$key] );
}
}
return $form_items;
}
add_filter( 'pdbcff-form_item_definitions', 'pdbcfa_modify_form_fields' );
@xnau
Copy link
Author

xnau commented Apr 9, 2018

Additional information on using regex patterns to validate the input:

http://html5pattern.com/Phones

Good place to test and debug your regex patterns:

https://regex101.com/

@xnau
Copy link
Author

xnau commented Jun 8, 2023

Edited to demonstrate use of the pdbcff-form_item_definitions filter to modify the internal fields.

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