Last active
June 8, 2023 22:20
-
-
Save xnau/43d3585c1d46bc54ad2fbbb7fb0dca03 to your computer and use it in GitHub Desktop.
Demonstrates how to add fields to a Participants Database Contact Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
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
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/