• Resolved Tech4Eleven

    (@tech4eleven)


    I used this article (https://givewp.com/documentation/developers/customizing-the-required-donation-form-fields/) to make the donor comments box required. The code below is in my functions.php and it works perfectly.

    I have 2 forms. On one form I have the donor comment box enabled but on the other form, I have it disabled. However, when someone fills out the form (link to my page above), an error shows on the page saying “Error: Please enter where you want this donation designated in the comment box. See notice above for details.”

    What do I need to adjust in my code below or is there no way around this?

    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_purchase_form_required_fields', 'mycustomprefix_give_form_required_fields' );
    

    thanks.

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Matt Cromwell

    (@webdevmattcrom)

    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!

    Thread Starter Tech4Eleven

    (@tech4eleven)

    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?

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    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?

    Thread Starter Tech4Eleven

    (@tech4eleven)

    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!

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    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.

    Thread Starter Tech4Eleven

    (@tech4eleven)

    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/

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    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?

    Thread Starter Tech4Eleven

    (@tech4eleven)

    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.

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    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!

    Thread Starter Tech4Eleven

    (@tech4eleven)

    boom! that’s awesome. works perfectly. thanks so much!

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    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!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Donor Comment Required Issue’ is closed to new replies.