When it comes to creating a website, one of the most important features is the contact form. Contact Form 7 is a popular plugin for WordPress websites that allows users to create custom contact forms quickly and easily. However, one issue with the plugin is that it can send website addresses or URLs to the recipient of the form. This can cause security concerns, and it’s important to prevent this from happening.
There are several reasons why you should prevent Contact Form 7 from sending website addresses. First and foremost, it can be a security risk. If a hacker gains access to the contact form and sends a malicious link to the recipient, it can result in a compromised website or even a data breach. By disabling the ability to send URLs, you can reduce the risk of this happening and protect your website from potential harm.
In addition to security concerns, sending URLs in a contact form can also lead to spam. Spammers often use contact forms to send unsolicited messages, and including a website address can make it easier for them to do so. By removing the ability to send URLs, you can reduce the amount of spam you receive and ensure that the messages you do receive are legitimate.
Another reason to prevent Contact Form 7 from sending website addresses is to improve the user experience. When users fill out a contact form, they expect to receive a response that is relevant to their inquiry. Including a website address can be distracting and confusing, and it may lead to the recipient ignoring the message altogether. By removing website addresses from your contact form, you can ensure that your responses are concise and to the point, improving the user experience for your visitors.
In conclusion, preventing Contact Form 7 from sending website addresses is essential for website security, spam prevention, user experience, and website performance. By disabling this feature, you can ensure that your website remains safe, fast, and easy to use for all visitors. Take the time to review your contact form settings and make the necessary changes today to improve the overall quality of your website.
Add the following code in your functions.php of your theme:
It checks all text-input-fields of Contact Form 7 and prevents sending the mails if they contain links
// This is validation code to prevent contact form 7 to send links add_filter( 'wpcf7_validate_text', 'no_urls_allowed', 10, 3 ); add_filter( 'wpcf7_validate_text*', 'no_urls_allowed', 10, 3 ); add_filter( 'wpcf7_validate_textarea', 'no_urls_allowed', 10, 3 ); add_filter( 'wpcf7_validate_textarea*', 'no_urls_allowed', 10, 3 ); function no_urls_allowed( $result, $tag ) { $tag = new WPCF7_Shortcode( $tag ); $type = $tag->type; $name = $tag->name; $value = isset( $_POST[$name] ) ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) ) : ''; // If this is meant to be a URL field, do nothing if ( 'url' == $tag->basetype || stristr($name, 'url') ) { return $result; } // Check for URLs $value = $_POST[$name]; $not_allowed = array( 'http://', 'https://', 'www.', '[url', '<a ', ' seo ' ); foreach ( $not_allowed as $na ) { if ( stristr( $value, $na ) ) { $result->invalidate( $tag, 'URLs are not allowed' ); return $result; } } return $result; }
Code Source: https://gist.github.com/galbaras/db88efe5f80a7af68f02