Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to ensure a >10 input into a form field? 3

Status
Not open for further replies.

DiamondLil

Technical User
Jul 16, 2002
107
US
Hi all.
How can I make sure a user can only input a number > 10 (for example) into a required form field?

Thanks in advance!
Lil
 
This should work for you:
Code:
if ($_POST['formfield'] > 10) // or $_GET['formfield'] if you are using GET
{
// It was a valid value
}
else
{
// It wasn't a valid value
}
//Daniel
 
You could do some check with PHP on the form's action page...

if ($userinput<11) {
//Send the user back to the form page to reenter number
}

OR...

You could saunter over to the JavaScript help area and ask the same question. While you could do it in PHP as shown above, it requires another page to process the form submission. I have seen some JavaScript out there that checks fields as you enter them on a form. Invalid field entries receive instant pop-up warnings. I'm not able to offer any sample code because I am not well versed in JavaScript. I just know it has been done before.
 
Conversely, you can put JavaScript on the page which validates the input before the form can be submitted. ______________________________________________________________________
TANSTAAFL!
 
But you would still need the PHP to check the values, as everyone doesn't have JavaScript enabled and your JavaScript might not work on all versions and platforms. //Daniel
 
Ah - thank you all (and Daniel, thank you again as you have come to my rescue before). I'd like to stay away from the Javascript right now. Let me give it a shot with PHP. Thanks again.

Lil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top