• Resolved natiaz

    (@natiaz)


    Hi,

    I’m trying to customize the form for one of the gateways from my functions.php file.
    To do so I’ve use remove_action and add_action to get the form fields as I want and it looks fine. The problem comes with the form validation.

    Using the filter ‘give_purchase_form_required_fields’ I’ve set the require fields:

    `function custom_give_form_required_fields( $required_fields, $form_id) {

    $payment_mode = give_get_chosen_gateway( $form_id );

    if($payment_mode == ‘mypayment’ || $payment_mode == ‘offline’)
    {
    $required_fields[‘give_last’] = array(
    ‘error_id’ => ‘invalid_last_name’,
    ‘error_message’ => __( ‘Please enter your last name.’, ‘cooper-child’ )
    );

    $required_fields[‘card_address’] = array(
    ‘error_id’ => ‘invalid_card_address’,
    ‘error_message’ => __( ‘Please enter your address for billing purposes.’, ‘cooper-child’ )
    );

    $required_fields[‘user_dni’] = array(
    ‘error_id’ => ‘invalid_user_dni’,
    ‘error_message’ => __( ‘Please enter your DNI / NIF’, ‘cooper-child’ )
    );

    $required_fields[‘user_phone’] = array(
    ‘error_id’ => ‘invalid_user_phone’,
    ‘error_message’ => __( ‘Please enter your phone’, ‘cooper-child’ )
    );

    $required_fields[‘card_zip’] = array(
    ‘error_id’ => ‘invalid_zip_code’,
    ‘error_message’ => esc_html__( ‘Please enter your zip / postal code.’, ‘give’ )
    );
    }

    return $required_fields;
    }
    add_filter( ‘give_purchase_form_required_fields’, ‘custom_give_form_required_fields’ );`

    But when I send an empty form it only shows the zip and the terms of use errors.

    In addition, I want to show those new fields in the different reports and in the donants info, is this possible using the filters and actions?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Matt Cromwell

    (@webdevmattcrom)

    Hi there,

    Rearranging fields within the Give form can be problematic by itself. But if you’re able to switch the gateways with your fields rearranged then most likely that’s not an issue for you.

    Regarding the required alerts, since the only ones that are triggering are Give Core fields, and the others are your custom fields my guess would be that you should double-check the field names to make sure they correspond with what you have here. Perhaps there’s a prefix being added you should confirm?

    If you have a Gist of the custom fields I could work with this a bit more. Let me know if you have more insight.

    Thread Starter natiaz

    (@natiaz)

    Hi, I’ve found where is the problem, it seems that the filter give_purchase_form_required_fields doesn’t gives me the $form_id, it comes empty.

    I need the form_id to get the given gateway.

    Thanks

    Plugin Contributor Matt Cromwell

    (@webdevmattcrom)

    Thanks for the update, glad you got it worked out!

    Thread Starter natiaz

    (@natiaz)

    Hi, I wasn’t able to make it work, just found where is the problem.

    The filter give_purchase_form_required_fields doesn’t has the $form_id, it comes empty and that causes all the problem.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom Fields’ is closed to new replies.