- This topic is empty.
-
AuthorPosts
-
March 6, 2012 at 5:49 pm #37010
kblake
ParticipantI have an online form that allows a user to enter the email address they wish to send a message to and I’d like to block certain email addresses, like: gmail, hotmail, yahoo, etc from using the form. The site is in WP and I am using the plugin Contact Form 7 which doesn’t have the option to block email addresses and I have not found anything on WP’s forum as a solution. So I thought adding some php would resolve the issuse, however I don’t even know where to start. Any ideas would be great. Thanks.
March 6, 2012 at 11:51 pm #98327ccc630
MemberIf I can ask, what is the purpose of blocking those email hosts? You’ve listed three very popular domains which could lead to excluding a very large number of potential users. There may be an entirely legitimate reason to do so; I’m just curious.
March 7, 2012 at 2:14 pm #98391kblake
ParticipantI completley agree. The reason is my client has a site that allows kids to report bulling to a teacher and what is happening is students are sending messages to their friends. Since students use free email services my client would just like them blocked.
March 7, 2012 at 2:48 pm #98400ccc630
MemberGotcha; makes perfect sense. I’m assuming, then, that students would send the messages using a school-based email address ([email protected] or somesuch). I’m definitely not a wizard when it comes to regular expressions, but I found this thread:
http://www.phpfreaks.com/forums/index.php?topic=137584
which seems to be along the lines of what you’re looking for. The final script in that thread excludes a certain domain, but if all the legitimate messages would come from one domain, you could also modify it to only accept that one domain.
Hope it helps. :)
Chris
March 8, 2012 at 3:30 pm #98513kblake
ParticipantThanks for the help and suggestions. Since this is a public site and there are many schools with their own domain, I am thinking just adding a few common email domains would make the most sense.
I think I’m getting closer to resolving this. I added “if(strpos(strtolower…” (see code below) but I get the error “Parse error: syntax error, unexpected” when using this code. Any ideas on why? Or what I am missing?
function wpcf7_text_validation_filter( $result, $tag ) {
$type = $tag;
$name = $tag;
$_POST[$name] = trim( strtr( (string) $_POST[$name], "n", " " ) );
if ( 'text*' == $type ) {
if ( '' == $_POST[$name] ) {
$result = false;
$result[$name] = wpcf7_get_message( 'invalid_required' );
}
}
if ( 'email' == $type || 'email*' == $type ) {
if ( 'email*' == $type && '' == $_POST[$name] ) {
$result = false;
$result[$name] = wpcf7_get_message( 'invalid_required' );
}
if(strpos(strtolower( '' != $_POST[$name] && ! is_email( $_POST[$name] ),'[email protected]') ){
$result = false;
$result[$name] = wpcf7_get_message( 'invalid_email' );
}
}elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
$result = false;
$result[$name] = wpcf7_get_message( 'invalid_email' );
}
}
return $result;
}
?>March 8, 2012 at 8:17 pm #98543kblake
ParticipantThis is a public site and not specific to any one school. Anybody can use the site. To collect and manage every teacher’s email address from every school would be very cumbersome. If there is a way to block gmail, yahoo and hotmail email accounts that would be greatly helpful. Here is the link to the site in case anyone wants to check it out. http://bongokidz.com/report-bullying/
Thanks!
March 10, 2012 at 1:40 pm #98712March 14, 2012 at 3:05 pm #99081kblake
ParticipantI attempted to do something like this but it was rather advanced for my php skills. However, on WP’s forum I found a member who was extremely helpful and he provided the coded which was one of the methods I was attempting to use. Here is the link for those who may need it.
Please note that this is for the Contact Form 7 plugin in WP and you’ll need to modify the text.php file under the Validation filter comment (line 113) in the modules folder.
Thank you ccc630 for all your suggestions, they were very helpful and I learned a little more about php.
March 14, 2012 at 10:52 pm #99118ccc630
MemberGlad you were able to get it running — I was a teacher for quite a few years, so I know first-hand how important a service like this is (sadly enough).
October 15, 2014 at 12:27 am #186260ggsmartboy
ParticipantI’m very new to php and wordpress. I’m stuck with same problem. I need to filter free domains in only one contact form. @kbespinoza Can you say me step by step how you solve this problem ASAP.
October 15, 2014 at 7:53 am #186302__
Participant@ggsmartboy, you do realize that this discussion has been dead for two and a half years? That the OP hasn’t been active on the forums for almost as long?
These facts notwithstanding, you should start a new discussion for your question, rather than sidetracking someone else’s. Be sure to explain what you have already tried, and what problems you encountered, and include any relevant code.
If, on the other hand, you are simply looking for someone to do the work for you (or give you “step by step instructions,” which is effectively the same thing), then you should consider hiring someone. People here will be very happy to help you learn and solve your problems, but it’s not a “do this for me” kind of community.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.