My website has a contact form that uses PERL to send messages to me via an email service. I want to prevent sending messages that contain words such as "porn", "sex", etc. The present program looks like this:
$Name=param('Name'); $Organization=param('Organization'); $Email=param('Email'); $Phone=param('Phone'); $Message=param('Message'); $Number=param('Spam Number'); $Spam=param('Spam'); $Robot=param('Robot'); $Result=param('Result'); if ($Name eq ""||$Organization eq ""||$Email eq ""||$Phone eq ""||$Messag +e eq "") { print "The FORM is INCOMPLETE. All Fields Marked With An * Are Require +d"; exit; } if ($Number ne "$Spam") { print "You Entered An Incorrect Anti Spam Number. Please try again."; exit; } if ($Result ne "5") { print "You Entered An Incorrect Answer. Please try again."; exit; } if ($Robot ne "1") { print "The Form Is Not Complete. Please try again."; exit }
The part that sends the message was omitted.

I want establish an array that will contain prohibited words and then search the $Message. If $Message contains any of those words I want to print a response such as "Bad Words Not Permitted. Please try again." I have seen some examples of how to do all this but have not been able to get anything to work. Either the program responds to the first word in the array or nothing happens. Here's an example that I found and tried:

@forbidden =("porn","sex"); foreach $forbidden (@forbidden) { if ($Message =~/$forbidden/) { print "Bad Language Not Permitted";] exit;}
This works for the first word but not the second, and if neither are present the rest of the program does not work.

Can someone suggest a solution or tell me what I'm doing wrong? Any and all help will be appreciated.Tks!


In reply to Bad Language In Contact Messages by Milti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.