Solved

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

Posted on 2003-12-04
7
254 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
7 Comments
 
LVL 33

Accepted Solution

by:
sajuks earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:hart
Comment Utility
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
Comment Utility
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
Comment Utility
seems i am a bit late and misread sth. :-)
0
 

Author Comment

by:John Account
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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-…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now