Plugin Directory

Changeset 2139947


Ignore:
Timestamp:
08/15/2019 10:19:30 AM (7 years ago)
Author:
data8
Message:

Fixed application of advanced telephone validation options in Gravity Forms and WooCommerce

Location:
data8-validation-for-contact-form-7
Files:
12 added
5 edited

Legend:

Unmodified
Added
Removed
  • data8-validation-for-contact-form-7/trunk/data8-validation-for-contact-form-7.php

    r2135867 r2139947  
    55Description: This plugin integrates Data8 email, telephone, name and address validation in WooCommerce, Gravity Forms and Contact Form 7
    66Author: Data8
    7 Version: 2.1
     7Version: 2.2
    88Author URI: http://www.data-8.co.uk
    99*/
  • data8-validation-for-contact-form-7/trunk/includes/d8cf7_settings.php

    r2121310 r2139947  
    229229                </tr>
    230230                <tr>
    231                     <td><strong>Use Data8 Unusable validation</strong></td>
     231                    <td><strong>Use Data8 Unusable Name Validation</strong></td>
    232232                    <td style="text-align:center;">
    233233                        <label class="switch">
  • data8-validation-for-contact-form-7/trunk/includes/d8gf-validation.php

    r2121310 r2139947  
    3838}
    3939
    40 if (get_option('d8cf7_telephone_validation')) {
     40if (get_option('d8cf7_telephone_validation'))
    4141    add_filter( 'gform_field_validation', 'd8_validate_tel_gf', 10, 4 );
    42 }
    4342
    4443function startsWith($haystack, $needle) {
     
    7877                $allowedPrefixesInput = substr($class, 10);
    7978                $allowedPrefixArray = [];
    80                 if ($allowedPrefixesInput != '') {
     79                if ($allowedPrefixesInput != '')
    8180                    $allowedPrefixArray = explode("_", $class);
    82                 }
     81               
    8382                foreach ($allowedPrefixArray as &$prefix) {
    84                     if ($prefix != 'd8AllowedPrefixes'){
     83                    if ($prefix != 'd8AllowedPrefixes')
    8584                        $allowedPrefixes = ($allowedPrefixes == '' ? '+'.$prefix : $allowedPrefixes.','.'+'.$prefix);
    86                     }
    8785                }
    8886            }
     
    9290                $barredPrefixesInput = substr($class, 10);
    9391                $barredPrefixArray = [];
    94                 if ($barredPrefixesInput != '') {
     92                if ($barredPrefixesInput != '')
    9593                    $barredPrefixArray = explode("_", $class);
    96                 }
     94               
    9795                foreach ($barredPrefixArray as &$prefix) {
    98                     if ($prefix != 'd8BarredPrefixes_'){
     96                    if ($prefix != 'd8BarredPrefixes_')
    9997                        $barredPrefixes = ($barredPrefixes == '' ? '+'.$prefix : $barredPrefixes.','.'+'.$prefix);
    100                     }
    10198                }
    10299            }
     
    108105            'telephoneNumber' => $value,
    109106            'defaultCountry' => $country,
    110             'options' => array ('Option' => array(
    111                 array('Name' => 'UseMobileValidation', 'Value' => $mobile),
    112                 array('Name' => 'UseLineValidation', 'Value' => $line),
    113                 array('Name' => 'AllowedPrefixes', 'Value' => $allowedPrefixes),
    114                 array('Name' => 'BarredPrefixes', 'Value' => $barredPrefixes),
    115                 array('Name' => 'ApplicationName', 'Value' => 'WordPress')
    116             ))
     107            'options' => array (
     108                'UseMobileValidation' => $mobile,
     109                'UseLineValidation' => $line,
     110                'AllowedPrefixes' => $allowedPrefixes,
     111                'BarredPrefixes' => $barredPrefixes,
     112                'ApplicationName' => 'WordPress'
     113            )
    117114        );
    118115       
    119116        $d8cf7_ajax_key = get_option('d8cf7_ajax_key');
    120         if($d8cf7_ajax_key ==  ""){ return $result; }
     117        if($d8cf7_ajax_key ==  "")
     118            return $result;
    121119
    122120        $url = "https://webservices.data-8.co.uk/InternationalTelephoneValidation/IsValid.json?key=" . $d8cf7_ajax_key;
     
    128126        }
    129127    }
    130 
    131128    return $result;
    132129}
    133130
    134 if (get_option('d8cf7_email_validation_level')) {
     131if (get_option('d8cf7_email_validation_level'))
    135132    add_filter( 'gform_field_validation', 'd8_validate_email_gf', 10, 4 );
    136 }
    137133
    138134function d8_validate_email_gf( $result, $value, $form, $field ) {
     
    141137
    142138        $level = get_option('d8cf7_email_validation_level');
    143         if($level == "None"){ return $result; }
    144         if($level == ""){ $level = 'MX'; }
     139        if($level == "None")
     140            return $result;
     141        if($level == "")
     142            $level = 'MX';
    145143       
    146144        foreach ($classes as $class) {
     
    148146                $level = substr($class, 8);
    149147        }
    150        
    151148   
    152149        // Set up the parameters for the web service call:
     
    155152            'email' => $value,
    156153            'level' => $level,
    157             'options' => array ('Option' => array(
    158                 array('Name' => 'ApplicationName', 'Value' => 'WordPress')
    159             ))
     154            'options' => array (
     155                'ApplicationName' => 'WordPress'
     156            )
    160157        );
    161158       
    162159        $d8cf7_ajax_key = get_option('d8cf7_ajax_key');
    163         if($d8cf7_ajax_key ==  ""){ return $result; }
     160        if($d8cf7_ajax_key ==  "")
     161            return $result;
    164162
    165163        $url = "https://webservices.data-8.co.uk/EmailValidation/IsValid.json?key=" . $d8cf7_ajax_key;
     
    171169        }
    172170    }
    173 
    174171    return $result;
    175172}
    176173
    177 if (get_option('d8cf7_salaciousName')) {
     174if (get_option('d8cf7_salaciousName'))
    178175    add_filter( 'gform_field_validation', 'd8_validate_name_gf', 10, 4 );
    179 }
    180176
    181177function d8_validate_name_gf ( $result, $value, $form, $field ) {
    182178    if ( $field->type == 'name' ) {
    183  
    184179        // Input values
    185180        $prefix = rgar( $value, $field->id . '.2' );
     
    198193                'surname' => $last
    199194            ),
    200             'options' => array ('Option' => array(
    201                 array('Name' => 'ApplicationName', 'Value' => 'WordPress')
    202             ))
     195            'options' => array (
     196                'ApplicationName' => 'WordPress'
     197            )
    203198        );
    204199        $d8cf7_ajax_key = get_option('d8cf7_ajax_key');
    205         if($d8cf7_ajax_key ==  ""){ return $result; }
     200        if($d8cf7_ajax_key ==  "")
     201            return $result;
    206202
    207203        $url = "https://webservices.data-8.co.uk/SalaciousName/IsUnusableName.json?key=" . $d8cf7_ajax_key;
     
    211207            $result['is_valid'] = false;
    212208            $result['message'] = "Invalid name.";
    213            
    214         }
    215     }
    216    
     209        }
     210    }
    217211    return $result;
    218212}
  • data8-validation-for-contact-form-7/trunk/includes/d8wc-validation.php

    r2121310 r2139947  
    1818function d8wc_validate(){
    1919    // telephone validation
    20     if(get_option('d8cf7_telephone_validation')){
     20    if(get_option('d8cf7_telephone_validation'))
    2121        d8wc_validate_tel('billing_phone');
    22     }
    2322
    2423    // email validation
    25     if(get_option('d8cf7_email_validation_level') && get_option('d8cf7_email_validation_level') !== "None"){
     24    if(get_option('d8cf7_email_validation_level') && get_option('d8cf7_email_validation_level') !== "None")
    2625        d8wc_validate_email('billing_email');
    27     }
    2826
    2927    // name validation
    3028    if(get_option('d8cf7_salaciousName')){
    31         if(array_key_exists ('billing_first_name', $_POST)){
     29        if(array_key_exists ('billing_first_name', $_POST))
    3230            d8wc_validate_name(array('billing_first_name', 'billing_last_name'));
    33         }
    34         if(array_key_exists ('shipping_first_name', $_POST)){
     31       
     32        if(array_key_exists ('shipping_first_name', $_POST))
    3533            d8wc_validate_name(array('shipping_first_name', 'shipping_last_name'));
    36         }
     34       
    3735    }
    3836}
    3937
    4038function d8wc_validate_tel($name) {
    41 
    4239    $value = isset( $_POST[$name] )
    4340        ? trim( strtr( (string) $_POST[$name], "\n", " " ) )
     
    5552        $mobile = 'false';
    5653
    57     if ('' == $value) {
     54    if ('' == $value)
    5855        return;
    59     } elseif ( '' != $value) {
    60 
     56    elseif ( '' != $value) {
    6157        $d8cf7_ajax_key = get_option('d8cf7_ajax_key');
    6258
     
    6864                'telephoneNumber' => $value,
    6965                'defaultCountry' => $country,
    70                 'options' => array ('Option' => array(
    71                     array('Name' => 'UseMobileValidation', 'Value' => $mobile),
    72                     array('Name' => 'UseLineValidation', 'Value' => $line),
    73                     array('Name' => 'ApplicationName', 'Value' => 'WordPress')
    74                 ))
     66                'options' => array (
     67                    'UseMobileValidation' => $mobile,
     68                    'UseLineValidation' => $line,
     69                    'ApplicationName' => 'WordPress'
     70                )
    7571            );
    7672            $url = "https://webservices.data-8.co.uk/InternationalTelephoneValidation/IsValid.json?key=" . $d8cf7_ajax_key;
    7773            $wsresult = ajaxAsyncRequest($url, $params);
    7874
    79             if ($wsresult['Status']['Success'] && $wsresult['Result']['ValidationResult'] == 'Invalid'){
     75            if ($wsresult['Status']['Success'] && $wsresult['Result']['ValidationResult'] == 'Invalid')
    8076                wc_add_notice(__('Invalid telephone number. If the number is correct, try adding the area code i.e. +44 for UK'), 'error' );
    81             }
    8277        }
    8378    }
     
    8580
    8681function d8wc_validate_email($name) {
    87 
    8882    $value = isset( $_POST[$name] )
    8983        ? trim( strtr( (string) $_POST[$name], "\n", " " ) )
     
    9387
    9488    if($level != "None"){
    95         if ($level == ''){
     89        if ($level == '')
    9690            $level = "MX";
    97         }
    9891
    99         if ('' == $value) {
     92        if ('' == $value)
    10093            return;
    101         } elseif ( '' != $value) {
    102 
     94        elseif ( '' != $value) {
    10395            $d8cf7_ajax_key = get_option('d8cf7_ajax_key');
    10496           
     
    111103                    'email' => $value,
    112104                    'level' => $level,
    113                     'options' => array ('Option' => array(
    114                         array('Name' => 'ApplicationName', 'Value' => 'WordPress')
    115                     ))
     105                    'options' => array (
     106                        'ApplicationName' => 'WordPress'
     107                    )
    116108                );
    117109                $url = "https://webservices.data-8.co.uk/EmailValidation/IsValid.json?key=" . $d8cf7_ajax_key;
    118110                $wsresult = ajaxAsyncRequest($url, $params);
    119111
    120                 if ($wsresult['Status']['Success'] && $wsresult['Result'] == 'Invalid'){
     112                if ($wsresult['Status']['Success'] && $wsresult['Result'] == 'Invalid')
    121113                    wc_add_notice(__('Invalid email address.'), 'error' );
    122                 }
    123114            }
    124115        }
     
    127118
    128119function d8wc_validate_name ($nameArray) {
    129 
    130120    $firstValue = isset( $_POST[$nameArray[0]] )
    131121        ? trim( strtr( (string) $_POST[$nameArray[0]], "\n", " " ) )
     
    136126    : '';
    137127       
    138     if ('' == $firstValue){
     128    if ('' == $firstValue)
    139129        return;
    140     }
    141     if ('' == $lastValue) {
     130   
     131    if ('' == $lastValue)
    142132        return;
    143     }
    144133
    145134    if('' != $firstValue && '' != $lastValue) {
    146 
    147135        $d8cf7_ajax_key = get_option('d8cf7_ajax_key');
    148136
     
    159147                'surname' => $lastValue
    160148            ),
    161             'options' => array ('Option' => array(
    162                 array('Name' => 'ApplicationName', 'Value' => 'WordPress')
    163             ))
     149            'options' => array (
     150                'ApplicationName' => 'WordPress'
     151            )
    164152        );
    165153        $url = "https://webservices.data-8.co.uk/SalaciousName/IsUnusableName.json?key=" . $d8cf7_ajax_key;
  • data8-validation-for-contact-form-7/trunk/readme.txt

    r2135867 r2139947  
    122122* Fixed application of advanced telephone validation options & defaults
    123123
     124= 2.2 =
     125* Fixed application of advanced telephone validation options in Gravity Forms and WooCommerce
     126
    124127== Upgrade Notice ==
    125128
     
    154157* Fixed application of advanced telephone validation options & defaults
    155158
     159= 2.2 =
     160* Fixed application of advanced telephone validation options in Gravity Forms and WooCommerce
     161
    156162== Screenshots ==
    1571631. Configuration screen
Note: See TracChangeset for help on using the changeset viewer.