• Resolved tbverrall

    (@tbverrall)


    Hi there,

    We are required to have last names when collecting donations for our financial disclosure.

    I saw a previous thread that provided a PHP snippet for making last name fields required on our form.

    Based on the description, it sounds like this snippet will do what I need it to do but I don’t have much experience with PHP. I don’t know which .php file to update in the plugin or where in that file I would need to insert the code (I’m not sure if PHP syntax requires things in a certain order).

    Any clarification would be greatly appreciated. We need to have this form fully live and functional asap.

    For reference this was the code:

    <?php
    
    /**
     * Require Last Name Snippet.
     *
     * Adds asterisk and error validation to the last name field of all Give forms.
     *
     * @param $required_fields
     * @param $form_id
     *
     * @return mixed
     */
    function give_require_last_name( $required_fields, $form_id ) {
    
    	$required_fields['give_last'] = array(
    		'error_id'      => 'invalid_last_name',
    		'error_message' => __( 'Please enter your last name', 'give' )
    	);
    	
    	//If restricting by gateway:
    	$stripe = give_is_gateway_active( 'give-stripe' );
    
    	if ($stripe) {
    		$required_fields['card_state'] = array(
    			'error_id'      => 'invalid_card_state',
    			'error_message' => __( 'Please enter your Credit Cards billing State.', 'give-stripe' )
    		);
    	}
    
    	return $required_fields;
    }
    
    add_filter( 'give_donation_form_required_fields', 'give_require_last_name', 10, 2 );

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

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to make last name field required (where to put the PHP snippet?)’ is closed to new replies.