Created
March 17, 2022 08:29
-
-
Save developer-anuragsingh/8354dca8267aa1b9daad63e2e32df3e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Validate CF7 text field for name | |
| function custom_name_field_validation_filter($result, $tag) { | |
| $type = $tag['type']; | |
| $name = $tag['name']; | |
| //here textbox type name is 'subject' | |
| if($name == 'first-name' || $name == 'last-name') { | |
| $value = $_POST[$name]; | |
| if (preg_match('/[\^£$%*()}{#~><>|=_+¬]/', $value)){ | |
| $result->invalidate( $tag, "Invalid characters." ); | |
| } | |
| } | |
| return $result; | |
| } | |
| add_filter('wpcf7_validate_text','custom_name_field_validation_filter', 10, 2); | |
| add_filter('wpcf7_validate_text*', 'custom_name_field_validation_filter', 10, 2); | |
| // Validate CF7 text field | |
| function custom_text_validation_filter($result, $tag) { | |
| $type = $tag['type']; | |
| $name = $tag['name']; | |
| //here textbox type name is 'subject' | |
| if($name == 'city' || $name == 'state' || $name == 'zip') { | |
| $value = $_POST[$name]; | |
| if (preg_match('/[\'^£$%&*()}{@#~><>|=_+¬]/', $value)){ | |
| $result->invalidate( $tag, "Invalid characters." ); | |
| } | |
| } | |
| return $result; | |
| } | |
| add_filter('wpcf7_validate_text','custom_text_validation_filter', 10, 2); | |
| add_filter('wpcf7_validate_text*', 'custom_text_validation_filter', 10, 2); | |
| // Validate CF7 textarea | |
| function custom_textarea_validation_filter($result, $tag) { | |
| $type = $tag['type']; | |
| $name = $tag['name']; | |
| if($name == 'message' || $name == 'address') { | |
| $value = $_POST[$name]; | |
| if (preg_match('/[\'^£$%&*()}{@#~><>|=_+¬]/', $value)){ | |
| $result->invalidate( $tag, "Invalid characters." ); | |
| } | |
| } | |
| return $result; | |
| } | |
| // add_filter('wpcf7_validate_textarea','custom_textarea_validation_filter', 10, 2); | |
| // add_filter('wpcf7_validate_textarea*', 'custom_textarea_validation_filter', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment