1

Is there any way to validate website field entered is right or wrong through Contact form 7?

Please help me.

3

Contact form 7 is awesome, so yes you can add your own custom validation :-).

More info here.


Here's a working and tested example for your situation:

Use [text* your-website] inside your contact form 7 form.

Add this snippet to your theme's functions.php, use a child-theme!

add_filter( 'wpcf7_validate_text*', 'custom_website_validation_filter', 20, 2 );
function custom_website_validation_filter( $result, $tag ) {
  if ( $tag->name == 'your-website' ) {

    $domain = isset( $_POST['your-website'] ) ? trim( $_POST['your-website'] ) : '';

    if ( ! checkdnsrr($domain, 'ANY') ) { // Check DNS records corresponding to a given Internet host name or IP address
      $result->invalidate( $tag, "We cannot find an active dns record for that website url?" );
    }
  }
  return $result;
}

Regards, Bjorn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.