• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Ban certain words from being submitted by a form, but also preventing the form from being sent...

Hi,

I have a dating site.  There is this form on the site where members can send messages to one another.  That form is being screened for email addresses if the member is not a paying member and returns an error message. This is all done by a javascript that I found on here ( God, experts are good!)

this is in my <head> tag

<script>
function check(str)
{
 reg= new RegExp("hotmail|yahoo|com|net|org|dot","i")
 if (reg.test(str)) alert("Your message contains either an email address or a web address. You are not allowed to include an email address or a web url in your message with a default membership.  If you want to give out your email address to other members, please upgrade your membership.")
}
</script>

Now here is my problem... My form uses this

<?
if ($result2 == 'default') {

          echo '<input type="submit" name="Submit2" value="Send" onclick="check(message.value)">';

} else {                   
      
          echo '<input type="submit" name="Submit2" value="Send">';

}
?>

the thing is, if the membership type is default, it does look for my forbidden words and does display the error message, but still sends the message...  I DON'T WANT IT TO SEND... I want the action to be cancelled...

 I tried changing the "input type=submit" to "input type=button" but that doesn't send my message if the membership is not default... What to do, what to do???

Any ideas, experts?

Julia
0
John Account
Asked:
John Account
1 Solution
 
sajuksCommented:
function check(str)
{
reg= new RegExp("hotmail|yahoo|com|net|org|dot","i")
if (reg.test(str))
{
alert("Your message contains either an email address or a web address. You are not allowed to include an email address or a web url in your message with a default membership. If you want to give out your email address to other members, please upgrade your membership.");
return false;
}
return true;
}

and

<form name="myform" onSubmit="return check(document.myform.myname.value)"
0
 
hartCommented:
ok in u form tag do this

<?
if ($result2 == 'default') {

          echo '<form name="frm" action="send.php" method="post" onsubmit="return check(document.frm.message.value)">';

} else {                
   
          echo '<form name="frm" action="send.php" method="post" >';

}
?>

and in ur script

<script>
function check(str)
{
    reg= new RegExp("hotmail|yahoo|com|net|org|dot","i")
    if (reg.test(str))
    {
        alert("Your message contains either an email address or a web address. You are not allowed to include an email address or a web url in your message with a default membership.  If you want to give out your email address to other members, please upgrade your membership.")
       return false;
   }
}
</script>


0
 
NetGrooveCommented:
You mixed up server side php scripting and browser side JavaScript scripting.

I would recommand to do the blocking on server side in php.
To get the support for php validation and blocking let this question be moved to php topic area by Community Support:
http://oldlook.experts-exchange.com/Community_Support/

Cheers,
NetGroove

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hartCommented:
oh i am late ;-)

just to tell u ur submit button would be just

echo '<input type="submit" name="Submit2" value="Send">';

without any conditions

Regards
Hart
0
 
ho_alanCommented:
um... maybe two approaches

1. <input type=submit name=submitz onsubmit="return check(message.value)" value=send>

//in  the function check, return true or false by checking message.value
//true, the form is sent, false, the form won't be sent

2. <input type=button name=send onclick="check(message.value)">
//in the function check, add "document.forms[0].submit()" if the condition is true

hope this can inspire u :-)
0
 
ho_alanCommented:
seems i am a bit late and misread sth. :-)
0
 
John AccountAuthor Commented:
Thank you for your answer... that works just fine... EXEPT...

I'll give you another 250 points for this question now...

It stops all the words CONTAINING org, com, net in it... so, for example, should I  want to send a message telling someone that I had the most unbelievable 'orgasm' last night, it doesn't work...LOL

I need it to look for an exact match...


Julia
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now