Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple form and PHP to redirect user to a new webpage on form postback
<?
if(isset($_POST['submit'])) {
$loc = "Location: " . $_POST['newPage'];
header($loc);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
Going To A New URL Via A Drop-Down List: JavaScript And DOM, PHP, ASP.NET
Copyright 2007 Doug Vanderweide
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Going To A New URL Via A Drop-Down List: JavaScript And DOM, PHP, ASP.NET Example 1: Via JavaScript / DOM</title>
<link href="../demo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
Going To A New URL Via A Drop-Down List:<br />
JavaScript And DOM, PHP, ASP.NET<br />
Example 2: Via PHP
</h1>
<form id="jumpForm" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<label>Select A Page:&nbsp;
<select id="newPage" name="newPage">
<option value="index.html" selected="selected">This page</option>
<option value="test.html">Another page, this directory</option>
<option value="../js_ddl_iframe/index.html">Another page, another directory, relative address</option>
<option value="http://www.dougv.com/demo/js_select_images/">Another page, another directory, absolute address</option>
<option value="http://answers.yahoo.com">Another domain</option>
</select>
</label>
<input type="submit" name="submit" id="submit" value="Go!" />
</form>
<p>Selecting a location above and clicking on the Go! button will take you to another page. Use your browser's Back button to return here.</p>
<p><a href="index.html">Example 1: Via JavaScript / DOM</a></p>
<p><a href="http://www.dougv.com/blog/2007/06/22/going-to-a-new-url-via-a-drop-down-list-javascript-and-dom-php-aspnet/">Going To A New URL Via A Drop-Down List: JavaScript And DOM, PHP, ASP.NET</a></p>
<p>&nbsp;</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.