Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Alnatroz75018

    (@alnatroz75018)

    Thanks guys for your prompt and valuable responses
    I indeed updated the plugin and this is now working fine
    Cheers

    Thread Starter Alnatroz75018

    (@alnatroz75018)

    Thank you RavanaH for your quyick response,
    however I checked the shortcode and it shows [ and ] and not the & #091; and & #093; (without the spaces).
    Do you think it is due to the plugin I use which somehow changes it to & #091; and & #093; ? Do you know if there is a way to force it to keep [ and ]?
    I am using css3 web pricing tables grids plugin with the following code:

    <a href="#contact_form_pop"> Let's chat </a>
    <div class="fancybox-hidden" style="display: none">
    <div id="contact_form_pop">[contact-form-7 id="220" title="Contact form 1"]</div>
     </div>

    Thread Starter Alnatroz75018

    (@alnatroz75018)

    Thank you Tobias for your quick response

    I will do without:)

    Thread Starter Alnatroz75018

    (@alnatroz75018)

    thank you Takayuki, I used the following code if this can help someone and it works

    add_filter('wpcf7_validate_text','postcode_custom_filter', 10, 2); // postcode field
    add_filter('wpcf7_validate_text*', 'postcode_custom_filter', 10, 2); // Req. postcode field
    // Add custom validation for CF7 form fields on postcode
    
    function postcode_in_area($postcode){ // check if the postcode is in our area
    	$areaArray = array('75001', '75002', '75003', '75004');
    
        if (!in_array($postcode, $areaArray)) {
                return true; // It's an area we operate in
    	}else{
    		return false; // It's an area we do NOT service
    	}
    }
    
    function postcode_custom_filter($result,$tag){
    	$type = $tag['type'];
    	$name = $tag['name'];
    	if('postcode' == $name){ // Only apply to fields with the form field name of "postcode"
    		$the_value = $_POST[$name];
    		if( postcode_in_area($the_value)){ // Is not in our area
    			$result['valid'] = false;
    			$result['reason'][$name] = "Sorry, we do not operate in this area.";
    		}
    	}
    	return $result;
    }
    Thread Starter Alnatroz75018

    (@alnatroz75018)

    Hi again,

    I believe the error comes from “preg_match”, as it is probably not the best way to check the exact value of the postcode. Is there a way to have a list of postcodes and match the result entered in the form against these values?

    Thank you in advance

    Thread Starter Alnatroz75018

    (@alnatroz75018)

    Dear Takayuki,
    thank you for looking into my issue.

    I have done the modification (this time in the plugin editor in WP)

    Unfortunatly it does not seem to work. whatever I populate in the postcode field, the circular arrows keep turning and nothing happens

    the modified code is the following

    add_filter('wpcf7_validate_text','postcode_custom_filter', 10, 2); // postcode field
    add_filter('wpcf7_validate_text*', 'postcode_custom_filter', 10, 2); // Req. postcode field
    // Add custom validation for CF7 form fields on postcode
    
    function postcode_in_area($postcode){ // check if the postcode is in our area
    	if(
    		preg_match('2010', $postcode) ||
    		preg_match('2011', $postcode) ||
    		preg_match('2013', $postcode) ||
    		preg_match('2014', $postcode) ||
    		preg_match('2015', $postcode) ||
    		preg_match('2016', $postcode) ||
    		preg_match('2017', $postcode) ||
    		preg_match('2018', $postcode) ||
    		preg_match('2019', $postcode)
    	){
    		return true; // It's an area we operate in
    	}else{
    		return false; // It's an area we do NOT service
    	}
    }
    
    function postcode_custom_filter($result,$tag){
    	$type = $tag['type'];
    	$name = $tag['name'];
    	if('postcode' == $name){ // Only apply to fields with the form field name of "postcode"
    		$the_value = $_POST[$name];
    		if( postcode_in_area($the_value)){ // Is not in our area
    			$result['valid'] = false;
    			$result['reason'][$name] = "sorry we do not operate in this area";
    		}
    	}
    	return $result;
    }
Viewing 6 replies - 1 through 6 (of 6 total)