Hi there,
Thanks for the heads up on that, the doc had an outdated filter. This is the correct and updated function you should use instead of what you have above:
function mycustomprefix_give_form_required_fields( $required_fields ) {
//Donor Comment
$required_fields['give_comment'] = array(
'error_id' => 'invalid_comment',
'error_message' => __( 'Please enter where you want this donation designated in the comment box. See notice above for details.', 'give' )
);
return $required_fields;
}
add_filter( 'give_donation_form_required_fields', 'mycustomprefix_give_form_required_fields' );
Thanks!
thanks for the quick reply! i have the above code entered into my site but unfortunately i see the same error. can you please help me out more?
Make sure the previous snippet is REMOVED and the new one is the only one present. Can you provide a screenshot of how you’ve entered the code into your site?
Yes, the old incorrect code is removed. Here is a screenshot: https://dev.bridgesofhopewestafrica.com/wp-content/uploads/2019/04/givewp.png
thanks for the help!
I would trim it down to the exact code I provided above first. Confirm that works as intended first.
Then add the last name, and confirm that BOTH work as intended.
Then NO NEED to do the Email one, because the email field is already required.
good idea. so i removed my code and just added the code you mentioned above and i still get the error stating “Please enter where you want this donation designated in the comment box. See notice above for details” – which is the error msg i wrote in functions.php to show if someone doesnt fill out the comment box, but of course, the comment box is disabled on the form on https://dev.bridgesofhopewestafrica.com/sponsor-a-student/
OK… I think there’s a misunderstanding. You want the comment to be REQUIRED, right? But on that ONE form you want it NOT required. If that’s the case, then you need to wrap the code in a if
conditional statement that checks against the form_id
.
Before I help with that guidance, can you confirm? There’s a form somewhere that you have comments enabled on, that you want to require it for, but NOT that one that you just linked to. Is that correct?
Mostly correct, yes. I have another form on my site that shows the donor comment box and I want it to be required. But on the form that is mentioned here, I do not have a comment box and thus do not want it required.
OK then. Here’s what you need to do.
1. Grab the FORM ID of each of the forms that you WANT to have the comment box required.
2. Use this updated snippet, and replace the '123', '456'
with the form IDs of your forms.
function mycustomprefix_give_form_required_fields( $required_fields, $form_id ) {
//Donor Comment
$forms = array('123','456');
if ( in_array($form_id, $forms) ) {
$required_fields['give_comment'] = array(
'error_id' => 'invalid_comment',
'error_message' => __( 'Please enter where you want this donation designated in the comment box. See notice above for details.', 'give' )
);
}
return $required_fields;
}
add_filter( 'give_donation_form_required_fields', 'mycustomprefix_give_form_required_fields', 10, 2 );
That will ensure that the requirement is ONLY on the forms that you want and not on the other ones.
If you only have ONE form that it’s required on, just use the one number, like this:
$forms = array('123');
Thanks!
boom! that’s awesome. works perfectly. thanks so much!
Glad to hear it.
If you’re enjoying Give and appreciate our support, we’d love a kind review from you here:
https://wordpress.org/support/plugin/give/reviews/
Thanks!