Laguna Posted April 25, 2007 Share Posted April 25, 2007 Why is it not validating ?? <form id="form1" name="form1" method="post" action="DiagnosisSoup.php"> <div align="center">Temeprature <label> <input type="text" name="temp" /> </label> <p> <label> <input type="checkbox" name="running_nose" value="checkbox" /> Running nose</label> </p> <p> <label> <input type="submit" name="submitted" value="Submit" /> </label> </p> </div> </form> <? //if the form is submitted, process user input if (isset($_POST['submitted'])) { //verify user input $result = true; if (is_numeric($_POST['temp'])) { echo "Temperature should be numeric"; $ready = false; } //check as many conditions as you like if ($_POST['temp']>42 || $_POST['temp']<30) { echo "You should be dead by now."; $ready = false; } //if all's well, process data if ($ready) { if ($_POST['temp']>37.5 && isset($_POST['running_nose'])) echo "You probably have cold."; } else DrawForm(); //data wasn't validated, so draw the form once again } else //form isn't submitted yet, so draw the form { DrawForm(); } function DrawForm() { include'testdiagnosis.php'; } ?> can anyone help ?? Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/ Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Share Posted April 25, 2007 what is the value of the temp input? Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238210 Share on other sites More sharing options...
Laguna Posted April 25, 2007 Author Share Posted April 25, 2007 i put in 42 for the input and it says Tempature should be numeric how come 42 is not numeric ?? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238211 Share on other sites More sharing options...
Laguna Posted April 25, 2007 Author Share Posted April 25, 2007 double post sorry Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238215 Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Share Posted April 25, 2007 Change it to this and tell me what happens: <form id="form1" name="form1" method="post" action="DiagnosisSoup.php"> <div align="center">Temeprature <label> <input type="text" name="temp" value="42"/> </label> <p> <label> <input type="checkbox" name="running_nose" value="checkbox" /> Running nose</label> </p> <p> <label> <input type="submit" name="submitted" value="Submit" /> </label> </p> </div> </form> Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238217 Share on other sites More sharing options...
Laguna Posted April 25, 2007 Author Share Posted April 25, 2007 Change it to this and tell me what happens: <form id="form1" name="form1" method="post" action="DiagnosisSoup.php"> <div align="center">Temeprature <label> <input type="text" name="temp" value="42"/> </label> <p> <label> <input type="checkbox" name="running_nose" value="checkbox" /> Running nose</label> </p> <p> <label> <input type="submit" name="submitted" value="Submit" /> </label> </p> </div> </form> it still says temperature is numeric Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238223 Share on other sites More sharing options...
Laguna Posted April 26, 2007 Author Share Posted April 26, 2007 Can anyone tell me why when put in numbers it still says temperature is numeric ?? Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-238737 Share on other sites More sharing options...
ballhogjoni Posted April 26, 2007 Share Posted April 26, 2007 post the DiagnosisSoup.php page code up please. Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239076 Share on other sites More sharing options...
Laguna Posted April 26, 2007 Author Share Posted April 26, 2007 post the DiagnosisSoup.php page code up please. <? //if the form is submitted, process user input if (isset($_POST['submitted'])) { //verify user input $result = true; if (is_numeric($_POST['temp'])) { echo "Temperature should be numeric"; $ready = false; } //check as many conditions as you like if ($_POST['temp']>42 || $_POST['temp']<30) { echo "You should be dead by now."; $ready = false; } //if all's well, process data if ($ready) { if ($_POST['temp']>37.5 && isset($_POST['running_nose'])) echo "You probably have cold."; } else DrawForm(); //data wasn't validated, so draw the form once again } else //form isn't submitted yet, so draw the form { DrawForm(); } function DrawForm() { include'testdiagnosis.php'; } ?> Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239092 Share on other sites More sharing options...
ToonMariner Posted April 26, 2007 Share Posted April 26, 2007 this code here if (is_numeric($_POST['temp'])) { echo "Temperature should be numeric"; $ready = false; } if $_POST['temp'] is a number it will echo out 'Temperature should be numeric' change it to if (!is_numeric($_POST['temp'])) { echo "Temperature should be numeric"; $ready = false; } Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239095 Share on other sites More sharing options...
Laguna Posted April 27, 2007 Author Share Posted April 27, 2007 oo i know i miss the if (!is_numeric($_POST['temp'])) { echo "Temperature should be numeric"; $ready = false; } but the problem is now it doesnt run this statement if ($ready) { if ($_POST['temp']>37.5 && isset($_POST['running_nose'])) echo "You probably have cold."; } must i declare $ready ?? Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239556 Share on other sites More sharing options...
Laguna Posted April 27, 2007 Author Share Posted April 27, 2007 double post sorry Link to comment https://forums.phpfreaks.com/topic/48647-php-validation/#findComment-239557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.