Solved

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

Posted on 2003-12-04
7
258 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

770 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