?
Solved

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

Posted on 2003-12-04
7
Medium Priority
?
263 Views
Last Modified: 2010-05-18
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
Comment
Question by:John Account
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 33

Accepted Solution

by:
sajuks earned 1000 total points
ID: 9880548
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
 
LVL 11

Expert Comment

by:hart
ID: 9880555
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
 
LVL 10

Expert Comment

by:NetGroove
ID: 9880558
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
Industry Leaders: 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!

 
LVL 11

Expert Comment

by:hart
ID: 9880563
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
 
LVL 5

Expert Comment

by:ho_alan
ID: 9880586
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
 
LVL 5

Expert Comment

by:ho_alan
ID: 9880588
seems i am a bit late and misread sth. :-)
0
 

Author Comment

by:John Account
ID: 9880646
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question