Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Form Problem, prevent submit if value="examplevalue"
gotcha41
post May 12 2005, 09:30 AM
Post #1


Advanced Member
*******

Group: Members
Posts: 142
Joined: 24-September 04
From: Belgium
Member No.: 1,260



i would like to have a code inserted to a form that prevents submitting if one of the inputfields (in particular) contains the value: "examplevalue" . Does anyone know the solution to this?

btw: the texts in other inputfields shouldn't be cleared if possible..

thanks in advance cool.gif
Go to the top of the page
 
+Quote Post
gotcha41
post May 12 2005, 09:32 AM
Post #2


Advanced Member
*******

Group: Members
Posts: 142
Joined: 24-September 04
From: Belgium
Member No.: 1,260



i didn't meant the value of one in particular input(text)field, but the text inside the textfield actually..

-sorry for the double post smile.gif
Go to the top of the page
 
+Quote Post
HmmZ
post May 12 2005, 09:56 AM
Post #3


Super Member
*********

Group: Members
Posts: 362
Joined: 2-March 05
From: The Netherlands
Member No.: 4,097



I think php-code would be the solution here (not completely sure)

<?php
$value="";
echo "<form action=\"xx\" method=\"post\">";
echo "<input type=\"text\" value=$value name=\"xx\">";


if($value=="examplevalue"){
echo "You are not allowed to insert that name";
}
?>

I know its not completely well written, but it globally shows how to do this(i think)
Go to the top of the page
 
+Quote Post
gotcha41
post May 12 2005, 10:07 AM
Post #4


Advanced Member
*******

Group: Members
Posts: 142
Joined: 24-September 04
From: Belgium
Member No.: 1,260



HmmZ: I think php-code would be the solution here (not completely sure)
...
I know its not completely well written, but it globally shows how to do this(i think)

ok thanks, i will try it out and post the results as soon as possible! cool.gif
Go to the top of the page
 
+Quote Post
theRealSheep
post May 12 2005, 12:30 PM
Post #5


Member [Level 1]
****

Group: Members
Posts: 69
Joined: 12-March 05
From: Australia
Member No.: 4,401



I use javascript for that same type of thing...
CODE
<script>
function checkField(value) {
if (value == "examplevalue") {
 alert("You cannot enter '" + value + "'");
 return false;
}
else return true;
}
</script>

then in your form tag you place an onSubmit call... where formName is the name of your form [as shown] and inputName is the name of the input field you want to check.
HTML
<form name="formName" onSubmit="return checkField(formName.inputName.value)">

This will not let the form submit if the value of inputName is equal to examplevalue.
Go to the top of the page
 
+Quote Post
cse-icons
post May 12 2005, 01:04 PM
Post #6


Super Member
*********

Group: Members
Posts: 351
Joined: 19-October 04
From: India
Member No.: 1,824



yup... you can use javascript for that.
the solution given by "theRealSheep" looks good.

If you want to compare with a substring or if the case is that the text should not contain "examplevalue" i.e, it should not be even part of it, you can use the index of function
Change the above code as follows:

CODE
if(value.indexOf("examplevalue")>-1){
alert("you cannot enter this");
// reset all other fields here if you want
 field1.value = '';
 field2.value = '';
...
}


Cheers.
Go to the top of the page
 
+Quote Post
electriic ink
post May 12 2005, 03:15 PM
Post #7


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,227
Joined: 11-February 05
From: Heaven
Member No.: 3,709



Don't use javascript, use php, cgi or asp but don't use javascript or html.

Why? Because it's so easy to get passed, all they have to do is viewsource and type in something else and eureaka they've passed.

------------------------------------
Assuming it's for a subscription form...
------------------------------------

If you use php, I recommend you should make it so they can't fill in the form again.

To do this you could:

1) Set a cookie
2) Add their ip address to a list of forbidden ips.

Go for number 2, preferably, as it's harder to pass as if you went for no. 1 they could just delete their cookies.

If you like any of these suggestions don't ask me because I know little php or cgi. I like asp biggrin.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics


 



- Lo-Fi Version Time is now: 6th October 2008 - 09:39 PM