refiking Posted April 21, 2008 Share Posted April 21, 2008 I want to check the values from a form to see if the user accidentally missed one of the fields. If they did, I want to show the form again. Here's what I have so far. As of right now, the form does not get displayed again if there is an error on the user's part. $season = $_POST['season']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $hour = $_POST['hour']; $min = $_POST['min']; $apm = $_POST['apm']; IF ($month == "Month"){ $month = ""; } IF ($day == "Day"){ $day = ""; } IF ($year == "Year"){ $year = ""; } IF ($hour == "Hour"){ $hour = ""; } IF ($min == "Minute"){ $min = ""; } include 'cont.php'; if(!isset($season) | !isset($month) | !isset($day) | !isset($year) | !isset($hour) | !isset($min)) { Link to comment https://forums.phpfreaks.com/topic/102138-im-stuck/ Share on other sites More sharing options...
monkeypaw201 Posted April 21, 2008 Share Posted April 21, 2008 Well, first off, try to make the subject a bit more... useful, not just "i need help" or "im stuck" onto the code... you are missing an if statement for 'apm' and try using the following code as the last line: if(!isset("$season") | !isset("$month") | !isset("$day") | !isset("$year") | !isset("$hour") | !isset("$min")) { not sure why, but sometimes things like that dont make sense (to me anyways..) but make code work.. Link to comment https://forums.phpfreaks.com/topic/102138-im-stuck/#findComment-522818 Share on other sites More sharing options...
craygo Posted April 21, 2008 Share Posted April 21, 2008 What you should do is hold your form in a variable <?php $form = "<form name=\"formname\" method=\"POST\" action=\"somepage.php\"> <input name=\"somename\" type=\"text\" value=\"".@$_POST['somename']."\" >"; // will put the value of the field if it has been submitted // continue on Then the page that checks for empty fields <?php $error = ""; forech($_POST as $key => $val){ if(empty($key)){ $error = "$key, "; } } if($error != ""){ echo "The following fields need to be fixed: $error<br>"; echo $form; } else { // process the form } ?> Granted this can be expanded upon but just to give you a very simple idea Ray Link to comment https://forums.phpfreaks.com/topic/102138-im-stuck/#findComment-522823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.