Jul 25, 2008

Form Problem - prevent submit if value="examplevalue"

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Form Problem - prevent submit if value="examplevalue"

gotcha41
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

Reply

gotcha41
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

Reply

HmmZ
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)

Reply

gotcha41
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

Reply

theRealSheep
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.

Reply

cse-icons
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.

Reply

electriic ink
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : prevent submit examplevalue

  1. Preventing A Form To Submit If A Field Is Empty? - (7)
  2. Submit Form Thorugh Jum Menu - (0)
    is it possible to submit a form if you click one of the options of a select drop down in the form,
    but each depending on which option you choose, the form is submitted to a different location. kinda
    like a jump menu submitting the form, to different 'locations' kvarner...



Looking for form, problem, prevent, submit, examplevalue

Searching Video's for form, problem, prevent, submit, examplevalue
advertisement



Form Problem - prevent submit if value="examplevalue"



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE