Plugin Directory

Changeset 1922330


Ignore:
Timestamp:
08/09/2018 02:36:40 PM (8 years ago)
Author:
data8
Message:

Added AllowedPPrefixes & BarredPrefixes parameters to Tel Val

Location:
data8-validation-for-contact-form-7/trunk/includes
Files:
3 edited

Legend:

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

    r1921629 r1922330  
    1818    $line = $tag->get_option( 'landline', '(true|false)', true );
    1919    $mobile = $tag->get_option( 'mobile', '(true|false)', true );
    20    
     20
     21    // Get the allowed prefixes
     22    $allowedPrefixesInput = $tag->get_option( 'allowedPrefixes', '', true );
     23    $allowedPrefixArray = [];
     24    if ($allowedPrefixesInput != '') {
     25        $allowedPrefixArray = explode("_", $allowedPrefixesInput);
     26    }
     27    $allowedPrefixes = '';
     28    foreach ($allowedPrefixArray as &$prefix) {
     29        $allowedPrefixes = ($allowedPrefixes == '' ? $prefix : $allowedPrefixes.','.$prefix);
     30    }
     31
     32    // Get the barred prefixes
     33    $barredPrefixesInput = $tag->get_option( 'barredPrefixes', '', true );
     34    $barredPrefixArray = [];
     35    if ($barredPrefixesInput != '') {
     36        $barredPrefixArray = explode("_", $barredPrefixesInput);
     37    }
     38    $barredPrefixes = '';
     39    foreach ($barredPrefixArray as &$prefix) {
     40        $barredPrefixes = ($barredPrefixes == '' ? $prefix : $barredPrefixes.','.$prefix);
     41    }
     42
    2143    if ($country == '')
    2244        $country = '44';
     
    4163            'options' => array ('Option' => array(
    4264                array('Name' => 'UseMobileValidation', 'Value' => $mobile),
    43                 array('Name' => 'UseLineValidation', 'Value' => $line)
     65                array('Name' => 'UseLineValidation', 'Value' => $line),
     66                array('Name' => 'AllowedPrefixes', 'Value' => $allowedPrefixes),
     67                array('Name' => 'BarredPrefixes', 'Value' => $barredPrefixes)
    4468            ))
    4569        );
  • data8-validation-for-contact-form-7/trunk/includes/d8cf7_instructions.php

    r1921629 r1922330  
    5353                        <li><strong>d8landline</strong> - if the telephone number is a UK landline, use the enhanced Landline Validation service to perform more detailed validation</li>
    5454                        <li><strong>d8country_US</strong> - if the telephone number does not include an explicit country code prefix, use the country specified in this option instead. Defaults to GB</li>
     55                        <li><strong>d8AllowedPrefixes_441_442</strong> - if specified any prefixes (without the leading plus "+" and seperated by an underscore "_") are the only ones allowed</li>
     56                        <li><strong>d8BarredPrefixes_44151_442</strong> - if specified any prefixes (without the leading plus "+" and seperated by an underscore "_") are barred</li>
    5557                    </ul>
    5658                </li>
     
    100102                        <li><strong>[tel* your-tel landline:true]</strong> - if the telephone number is a UK landline, use the enhanced Landline Validation service to perform more detailed validation</li>
    101103                        <li><strong>[tel* your-tel country:US]</strong> - if the telephone number does not include an explicit country code prefix, use the country specified in this option instead. Defaults to GB</li>
     104                        <li><strong>[tel* your-tel allowedPrefixes:+441_+442]</strong> - if included only these prefixes will be allowed</li>
     105                        <li><strong>[tel* your-tel barredPrefixes:+01_+447]</strong> - if included these prefixes will NOT be allowed</li>
    102106                    </ul>
    103107                </li>
  • data8-validation-for-contact-form-7/trunk/includes/d8gf-validation.php

    r1921629 r1922330  
    4949    if ( $field->get_input_type() === 'phone' && $result['is_valid'] && $value != '' ) {
    5050        $classes = explode(' ', $field->cssClass);
    51         $country = '44';
     51        $country = '44'; 
    5252        $line = 'false';
    5353        $mobile = 'false';
     54        $allowedPrefixes = '';
     55        $barredPrefixes = '';
    5456       
    5557        foreach ($classes as $class) {
     
    6264            if ($class == 'd8mobile')
    6365                $mobile = 'true';
     66           
     67            // Pull out a list of Allowed Prefixes (if specified)
     68            if (startsWith($class, 'd8AllowedPrefixes_')){
     69                $allowedPrefixesInput = substr($class, 10);
     70                $allowedPrefixArray = [];
     71                if ($allowedPrefixesInput != '') {
     72                    $allowedPrefixArray = explode("_", $class);
     73                }
     74                foreach ($allowedPrefixArray as &$prefix) {
     75                    if ($prefix != 'd8AllowedPrefixes'){
     76                        $allowedPrefixes = ($allowedPrefixes == '' ? '+'.$prefix : $allowedPrefixes.','.'+'.$prefix);
     77                    }
     78                }
     79            }
     80
     81            // Pull out a list of Barred Prefixes (if specified)
     82            if (startsWith($class, 'd8BarredPrefixes_')){
     83                $barredPrefixesInput = substr($class, 10);
     84                $barredPrefixArray = [];
     85                if ($barredPrefixesInput != '') {
     86                    $barredPrefixArray = explode("_", $class);
     87                }
     88                foreach ($barredPrefixArray as &$prefix) {
     89                    if ($prefix != 'd8BarredPrefixes_'){
     90                        $barredPrefixes = ($barredPrefixes == '' ? '+'.$prefix : $barredPrefixes.','.'+'.$prefix);
     91                    }
     92                }
     93            }
    6494        }
    6595       
     
    76106            'options' => array ('Option' => array(
    77107                array('Name' => 'UseMobileValidation', 'Value' => $mobile),
    78                 array('Name' => 'UseLineValidation', 'Value' => $line)
     108                array('Name' => 'UseLineValidation', 'Value' => $line),
     109                array('Name' => 'AllowedPrefixes', 'Value' => $allowedPrefixes),
     110                array('Name' => 'BarredPrefixes', 'Value' => $barredPrefixes)
    79111            ))
    80112        );
Note: See TracChangeset for help on using the changeset viewer.