Customizing the Required Donation Form Fields
Sometimes you may want to create additional form fields within your donation forms. Here’s how to customize which fields to make required.
You may want additional form fields to be required depending on how you plan on collecting donations. Here’s how to customize which fields are required, and the text that appears if the donor has forgotten to complete it.
The standard fields that are required are email and first name. If you have it user registration enabled then username and password are also required.
You can customize any fields to be required. For instance, here’s how to require the first and last name fields:
Customize GiveWP Required Donation Fields
/**
* GiveWP Form Require Fields
*
* @description: Cusomize the prefix of this function before using. The $required_fields array key is the name of the field you would like to make required; ie " name='card_address_2' " - find using Debug Tools, etc.
*
* @param $required_fields
*
* @return mixed
*/
function mycustomprefix_give_form_required_fields( $required_fields ) {
//First Name
$required_fields['give_first'] = array(
'error_id' => 'invalid_last_name',
'error_message' => __( 'Please enter your first name.', 'give' )
);
//Last Name
$required_fields['give_last'] = array(
'error_id' => 'invalid_last_name',
'error_message' => __( 'Please enter your last name.', 'give' )
);
//Uncomment to add Address
// $required_fields['card_address'] = array(
// 'error_id' => 'invalid_card_address',
// 'error_message' => __( 'Please enter your address for billing purposes.', 'give' )
// );
//ACustom Field
// $required_fields['my_custom_field'] = array(
// 'error_id' => 'invalid_my_custom_field',
// 'error_message' => __( 'Custom field required message.', 'give' )
// );
return $required_fields;
}
add_filter( 'give_donation_form_required_fields', 'mycustomprefix_give_form_required_fields' );