Create a script that displays a form allowing the user to select one of four GTC
ID: 3812300 • Letter: C
Question
Create a script that displays a form allowing the user to select one of four GTCC wesbsites — gtcc.edu, online.gtcc.edu, my.gtcc.edu, and ssp.gtcc.edu — and then jumps to the relevant site based on the user's choice. My script does not jump to the webste, what have I done wrong?
<?php
if ( isset( $_POST["submitButton"] ) ) {
switch ( $_POST["store"] ) {
case ".edu/":
header( "Location: http://www.gtcc.edu/" );
break;
case ".edu/":
header( "Location: http://www.online.gtcc.edu/" );
break;
case ".edu/":
header( "Location: http://www.my.gtcc.edu/" );
break;
case ".edu/":
header( "Location: http://www.ssp.gtcc.edu/" );
break;
}
} else {
displayForm();
}
function displayForm() {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>=GTCC WebSite Selector</title>
</head>
<body>
<h1>GTCC Website Selector</h1>
<form action="" method="post">
<div>
<label for="store">Choose your GTCC Website:</label>
<select name="store" id="store" size="1">
<option value=".edu">GTCC Homepage</option>
<option value=".edu">Moodle Login</option>
<option value=".edu">My GTCC ( Web Advisor)</option>
<option value=".edu">Access your SSP </option>
</select>
<div>
<input type="submit" name="submitButton" id="submitButton" value="Visit GTCC" />
</div>
</div>
</form>
<?php
}
?>
</body>
</html>
Explanation / Answer
// problem in your selected value with same keyword ".edu " and second thing that you are using slash with edu word (/) here is proper code for you to run that script
<?php
if ( isset( $_POST["submitButton"] ) ) {
switch ( $_POST["store"] ) {
case ".edu1":
header( "Location: http://www.gtcc.edu/" );
break;
case ".edu2":
header( "Location: http://www.online.gtcc.edu/" );
break;
case ".edu3":
header( "Location: http://www.my.gtcc.edu/" );
break;
case ".edu4":
header( "Location: http://www.ssp.gtcc.edu/" );
break;
}
} else {
displayForm();
}
function displayForm() {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>=GTCC WebSite Selector</title>
</head>
<body>
<h1>GTCC Website Selector</h1>
<form action="" method="post">
<div>
<label for="store">Choose your GTCC Website:</label>
<select name="store" id="store" size="1">
<option value=".edu1">GTCC Homepage</option>
<option value=".edu2">Moodle Login</option>
<option value=".edu3">My GTCC ( Web Advisor)</option>
<option value=".edu4">Access your SSP </option>
</select>
<div>
<input type="submit" name="submitButton" id="submitButton" value="Visit GTCC" />
</div>
</div>
</form>
<?php
}
?>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.