Created
January 18, 2019 20:18
-
-
Save mathetos/9247769bd31caef15655a225994e24cf to your computer and use it in GitHub Desktop.
GiveWP Custom field with validation
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
/** | |
* Add Custom Donation Form Fields | |
* | |
* @param $form_id | |
*/ | |
function give_myprefix_custom_form_fields( $form_id ) { | |
if ( $form_id == 8) { | |
//$forms = array( 8 ); | |
?> | |
<div id="give-referral-wrap"> | |
<label class="give-label" for="give-referral"><?php _e( 'Triath-a-Toddlers Name?:', 'give' ); ?><span class="give-required-indicator">*</span> <span class="give-tooltip icon icon-question" data-tooltip="<?php _e( 'Please tell us whom you are sponsoring.', 'give' ) ?>"></span> | |
</label> | |
<textarea class="give-textarea" name="give_referral" id="give-referral"></textarea> | |
</div> | |
<?php | |
} | |
} | |
add_action( 'give_after_donation_levels', 'give_myprefix_custom_form_fields', 10, 1 ); | |
/* | |
* Validate Custom Field | |
* | |
* Check for errors without custom fields | |
* | |
* @param $valid_data | |
* @param $data | |
*/ | |
function give_myprefix_validate_custom_fields( $required_fields, $form_id ) { | |
//$forms = array( 8 ); | |
if ( $form_id == 8 ) { | |
$required_fields['give_referral'] = array( | |
'error_id' => 'invalid_give_referral', | |
'error_message' => __( 'Please tell us whom you are sponsoring.', 'give' ), | |
); | |
} | |
return $required_fields; | |
} | |
add_filter( 'give_donation_form_required_fields', 'give_myprefix_validate_custom_fields', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment