473,809 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable form submit with illegal words

Jacotheron
44 New Member
I need a script that can disable the submit button on a form or prevent the form from being submitted when there is an illegal word or character in the text box. This should prevent a spam bot from sending links to me via my website's contact me function. Here is the form that I need to protect:
[HTML]
<form id="FormName" action="thehand ler.cgi" method="post" name="FormName" >

<p>Name: /Naam: <input type="text" name="name" size="24" /></p>
<p>Email: /E-pos: <input type="text" name="email" size="24" /></p>
<p>Message: /Boodskap:<br />
<textarea name="message" rows="4" cols="30"></textarea></p>
<p><input type="submit" name="Submit/stuur" value="Submit/Stuur" /></p>
</form>
[/HTML]

The message textarea is the field that should be checked. Unnecessary text were removed.
Aug 11 '08 #1
11 2313
acoder
16,027 Recognized Expert Moderator MVP
It won't prevent spam bots. Someone could just disable JavaScript.

Anyhow, the way to do this is in the normal validation way:
Expand|Select|Wrap|Line Numbers
  1. <form ... onsubmit="return validate()">
then validate() would return false if there are illegal words (and thereby prevent submission) and true otherwise.
Aug 11 '08 #2
RamananKalirajan
608 Contributor
Hi, what did you mean by Illegal words, You can validate the form as Mr. Coder suggested or if you want to be more specific. onKeyPress event for TextArea write your own logic, so that the user can only enter character without special symbol and numbers. This alone can be done u can't check what he entered is meaningful or not while the user enters the text over there. If any doubts post it back I will try to help you out

Regards
Ramanan Kalirajan
Aug 12 '08 #3
Jacotheron
44 New Member
Hi, what did you mean by Illegal words, You can validate the form as Mr. Coder suggested or if you want to be more specific. onKeyPress event for TextArea write your own logic, so that the user can only enter character without special symbol and numbers. This alone can be done u can't check what he entered is meaningful or not while the user enters the text over there. If any doubts post it back I will try to help you out

Regards
Ramanan Kalirajan
The illegal words/characters are to be specified in JS and be validated prior to form submit. How do I tell JS to check for it in the text area? That is where my problem is. The characters are: "<>?[]" The idea is to prevent them from sending me links to other sites i don't have time to visit. (these messages are about 120 k each to download and every day there are a lot of them)

Thank you for the help
Aug 15 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Use a regular expression, e.g. [<>\?\[\]], to test the input from the text area using the match() method.
Aug 16 '08 #5
RamananKalirajan
608 Contributor
The illegal words/characters are to be specified in JS and be validated prior to form submit. How do I tell JS to check for it in the text area? That is where my problem is. The characters are: "<>?[]" The idea is to prevent them from sending me links to other sites i don't have time to visit. (these messages are about 120 k each to download and every day there are a lot of them)

Thank you for the help
Just check this one. This may the thing what u are looking for

[HTML]<html>
<textarea onkeypress="ret urn checkThis(event )">
</textarea>
</html>
<script type="text/javascript">
function checkThis(e)
{
var ch = e.keyCode;
if(ch!=60&&ch!= 62&&ch!=63&&ch! =91&&ch!=93)
return true;
return false;
}
</script>[/HTML]

Regards
Ramanan Kalirajan
Aug 18 '08 #6
Jacotheron
44 New Member
Just check this one. This may the thing what u are looking for

[HTML]<html>
<textarea onkeypress="ret urn checkThis(event )">
</textarea>
</html>
<script type="text/javascript">
function checkThis(e)
{
var ch = e.keyCode;
if(ch!=60&&ch!= 62&&ch!=63&&ch! =91&&ch!=93)
return true;
return false;
}
</script>[/HTML]
I tried this script, but for some reason it does not prevent the use of illegal characters and it still gets through.

Thank you for the help
Aug 21 '08 #7
RamananKalirajan
608 Contributor
I tried this script, but for some reason it does not prevent the use of illegal characters and it still gets through.

Thank you for the help
Hello wether the code is showing any error. Or it doesn't restrict the illegal characters. The code was working fine for me. Please tell the problem u faced

Regards
Ramanan Kalirajan
Aug 22 '08 #8
Jacotheron
44 New Member
Hello wether the code is showing any error. Or it doesn't restrict the illegal characters. The code was working fine for me. Please tell the problem u faced
No code error is displayed and the submission is not prevented when entering the illegal characters.

Thank You for the help
Aug 26 '08 #9
RamananKalirajan
608 Contributor
No code error is displayed and the submission is not prevented when entering the illegal characters.

Thank You for the help

I dont know why that code was not working for you. But any how try this one. This amy surely help u out.

[HTML]<html>
<head>
<script type="text/javascript">
var flag=0;
function check(ths)
{
var x = new Array("<",">"," ?","[","]");
var data = ths.value;
for(var i=0;i<x.length; i++)
{
if(data.indexOf (x[i])>0)
{
alert("coming") ;
flag=1;
break;
}
flag=0;
}
if(flag==1)
document.getEle mentById('mysub mit').disabled= true;
else
document.getEle mentById('mysub mit').disabled= false;
}
</script>
</head>
<form action="demo.ht ml">
<textarea onkeyup="check( this)">
</textarea>
<br/>
<input type="submit" value="submit" id="mySubmit">
</form>
</html>[/HTML]

Regards
Ramanan Kalirajan
Aug 27 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
9308
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
3
3172
by: Jeff | last post by:
I have a payment form with a submit button. A large percentage of users double-click the submit button thus submitting their payment information twice. I would like to use javascript to disable the submit button once it's been clicked, yet still have the form submit. I can do this in ASP 2.0, however, ASP.Net seems to be adversely affected if you disable the submit button. Here's how I have it set up... The submit button is a...
4
4851
by: whyyyy | last post by:
USING IIS 5.1, and Windows XP pro, the following form works on my system, and I can use as many form elements as I wish, as long as all form elements have the same name: "words", in this example. Help -- why can`t I give each form element a different name? Any suggestions will be gratefully appreciated. Also,See example at very bottom of something that once worked on a remote server, but doesn't on IIS 5.1, windows xp pro
4
2739
by: kschneider | last post by:
Assume there's a form with it's action attribute all set to post to a URL, but without a submit control. Form submission is done via a link and I want to prevent the classic "double submit". Ignoring the server side of things, does anyone see any holes with the following script? It seems to work, but I'd appreciate other eyes on it. Maybe a try/catch/finally wrapper of some sort to be sure the link is re-enabled in the face of an...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.