Solved

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

Posted on 2003-12-04
7
262 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

688 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