Hy! I have a form where the user is able to select which attribute is going to be part of the query and has one field to insert the attributes value. This works fine. The only problem is that I have some troubles to do the input validation. So ensure that there is a attribute value is not the thing, but I can not check if the value is numeric because it could also be a date. Has somebody an idea how to solve this without changing the structure of the forms! <select name = "attribute"> <option value="ID">defined_area_id = </option> <option value="date">defined_area_date = </option> </selection> <input name = "values"> <input type="submit" value="submit"> Code (markup):
why don't you consider using the date() function http://in2.php.net/manual/en/function.date.php to submit the date and avoid users from messing around ?
I will have only very few users for my php project and therefore I think it is enough to give a field for entering a date and then I check the input using the checkdate() function. And I have not much experiance in PHP so I want to play a little with different solutions to get to know the language better. I have solved the task by myself. Maybe not elegant, but it works: if (!isset($_POST['fields']) || trim($_POST['fields']) == '') { die("Please choose a value"); } elseif (!isset($_POST['values']) || trim($_POST['values']) == '') { die("ERROR: please insert a value"); } elseif (is_numeric($_POST['values'])) { //die ("ERROR: Whatever you just said isn't a number!");} echo "You inserted a area ID of {$_POST['values']}";} else {$a = $_POST['values']; $parts = explode('.', $a); if (!checkdate($parts[1], $parts[0], $parts[2])) { die("ERROR: wrong input");}} Code (markup):