gotcha41 0 Report post Posted May 12, 2005 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 Share this post Link to post Share on other sites
gotcha41 0 Report post Posted May 12, 2005 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 Share this post Link to post Share on other sites
HmmZ 0 Report post Posted May 12, 2005 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) Share this post Link to post Share on other sites
gotcha41 0 Report post Posted May 12, 2005 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! Share this post Link to post Share on other sites
theRealSheep 0 Report post Posted May 12, 2005 I use javascript for that same type of thing... <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. <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. Share this post Link to post Share on other sites
cse-icons 0 Report post Posted May 12, 2005 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: if(value.indexOf("examplevalue")>-1){alert("you cannot enter this"); // reset all other fields here if you want field1.value = ''; field2.value = ''; ...} Cheers. Share this post Link to post Share on other sites
electriic ink 1 Report post Posted May 12, 2005 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 Share this post Link to post Share on other sites