Jump to content
xisto Community
gotcha41

Form Problem prevent submit if value=examplevalue

Recommended Posts

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 :P

Share this post


Link to post
Share on other sites

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

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! :P

Share this post


Link to post
Share on other sites

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

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

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 :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.