Example #1
0
				<br/>* indicates required field
			</form>
		<?php 
} else {
    if (empty($_POST['name']) || empty($_POST['username']) || empty($_POST['email']) || strpos($_POST['email'], '@') === FALSE) {
        if (empty($_POST['name'])) {
            echo "You didn't enter your name =(<br/>";
        }
        if (empty($_POST['username'])) {
            echo "You didn't enter your username =(<br/>";
        }
        if (empty($_POST['email']) || strpos($_POST['email'], '@') === FALSE) {
            echo "You didn't enter a valid email =(<br/>";
        }
        echo "<form action=\"" . htmlspecialchars($_SERVER['PHP_SELF']) . "\"><input type='submit' name='fail' value='Back to form' /></form>";
        exit;
    }
    $name = $_POST['name'];
    echo "Your name: {$name}<br/>";
    $username = $_POST['username'];
    echo "Your username: {$username}<br/>";
    $email = $_POST['email'];
    echo "Your email: {$email}<br/>";
    echo "<h3>Work access</h3><ul>";
    listIt(array($_POST['primary_browser'], $_POST['work_speed'], $_POST['work_OS']));
    echo "</ul><h3>Home access</h3><ul>";
    listIt(array($_POST['primary_home_browser'], $_POST['home_speed'], $_POST['home_OS']));
}
?>
</body>
</html>
					<?php 
    ckBox('sunshine', 'clouds', 'rain', 'hail', 'sleet', 'snow', 'wind', 'cold', 'heat', 'fog', 'humidity');
    //Fog, humidity added here.
    ?>
					<p />
					<!--New request for data from the user.-->
					<p>Anything else? Please list the additional weather conditions in box below, 
					separated by commas.</p>
					<input type="text" name="more" size="60" /><p />
					<input type="submit" name="submit" value="Go" />
				</form>
				<?php 
    //If form submitted, process input.
} else {
    //Retrieve the date and location information.
    $inputLocal = array($_POST['city'], $_POST['month'], $_POST['year']);
    echo "In {$inputLocal['0']} in the month of {$inputLocal['1']} {$inputLocal['2']}, you observed \n\t\t\t\tthe following weather:<br /> \n<ul>";
    /*Retrieve the user response. Creating these variables is not strictly necessary. 
    		You could just use the $_POST variable in the function, but creating separate 
    		variables makes your code easier to read. */
    isset($_POST['weather']) ? $weather = $_POST['weather'] : ($weather = array());
    $more = $_POST['more'];
    //Call the function for each response.
    listIt($weather);
    isset($_POST['more']) ? listIt($more) : '';
    //var_dump($weather);
    echo "</ul>";
}
?>
	</body>
</html>
Example #3
0
if (!isset($_POST['city'])) {
    ?>
		<h2>Describe weather you observed</h2>
		<form action="<?php 
    htmlspecialchars($_SERVER['PHP_SELF']);
    ?>
" method="POST">
		City: <input type="text" placeholder="city" name="city"/><br/>
		Month: <input type="text" placeholder="month" name="month" /><br/>
		Year: <input type="text" placeholder="year" name="year"/><br/>
		<?php 
    insertWeatherOptions("rain", "sunshine", "clouds", "hail", "sleet", "snow", "wind", "fog", "humidity");
    ?>
		<br/>Anything else?<br/>
		<input type="text" name="newWeather"/>
		<button type="submit">submit</button>
		</form>
	<?php 
} else {
    $location = array($_POST['city'], $_POST['month'], $_POST['year']);
    echo "In {$location['0']} in the month {$location['1']}, {$location['2']} you observed the following weather:";
    $weather = $_POST['weather'];
    $newWeather = $_POST['newWeather'];
    echo "<ul>";
    listIt($weather);
    listIt($newWeather);
    echo "</ul>";
}
?>
</body>
</html>