Home / Admin / How to Add Address Field Validation For Authorize.net
Duplicate Snippet

Embed Snippet on Your Site

How to Add Address Field Validation For Authorize.net

<10
Code Preview
php
<?php
/**
 * Add address validation for Authorize.net address fields
 *
 * @link https://wpforms.com/developers/how-to-add-address-field-validation-for-authorize-net/
 */
 
function wpf_dev_authorize_address_validation( $fields, $entry, $form_data ) {
       
    // Optional, you can limit to specific forms. Below, we restrict output to
    // form #1000.
    if ( absint( $form_data[ 'id' ] ) !== 1000 ) {
        return $fields;
    }
       
    // check the field ID 25 to see if it's empty and if it is, run the error    
    if ( strlen( $fields[25][ 'value' ] ) > 60 )
        {
            // Check the field ID 25 and show error message at the top of form and under the specific field
               wpforms()->process->errors[ $form_data[ 'id' ] ] [ '25' ] = esc_html__( 'The characters for the address line must not exceed 60.', 'plugin-domain' );
        }
    }
add_action( 'wpforms_process', 'wpf_dev_authorize_address_validation', 10, 3 );

Comments

Add a Comment