Ok, here's my ordeal; I'm hoping someone can point me in the right direction here. I've got a form which is a multi-page php wizard but each subsequent page is dependent upon the chosen option in a select box. I have it redirecting to the appropriate page when clicking submit based on the selection but the information is not being posted to the page. So my question is how can I post to both pages so that which ever one开发者_运维知识库 is loaded next can have the information entered in the previous. Here is an example of my current code.
<html>
<head></head>
<body>
<?php
//let's start the session
session_start();
//now, let's register our session variables
session_register('info from last page');
//finally, let's store our posted values in the session variables
$_SESSION['info from last page'] = $_POST['info from last page'];
echo $_SESSION["info from last page"];
//redirect to appropriate page based on selected option
function redirect($where){
header("Location: $where");
}
if ($_REQUEST['audio'] == 'option1'){
redirect('http://www.avwebcasting.com/ordering_system/webcast/step3ressless.php');
}elseif($_REQUEST['audio'] == 'option2'){
redirect('http://www.avwebcasting.com/ordering_system/webcast/step3oa.php');
}
?>
<form method="post" id="step2" name="step2" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label>
<span>*Audio:</span>
<select name="audio" class="select">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
</select>
</label>
<INPUT TYPE="submit" name="submit"/>
</body>
</html>
for starters the reason your session is not working is because your outputting data before session starts
<html> <<<
<head></head> <<<
<body> <<<
<?php
//let's start the session
session_start(); //this fails
This should be like so
<?php
//let's start the session
session_start(); //now it works :D
?>
<html>
<head></head>
<body>
You can in option value get name of php file to reditect, then you can use one line solution:
redirect('http://www.avwebcasting.com/ordering_system/webcast/' . stripslashes($_REQUEST['audio']) . '.php');
or I miss understand the question
This.
<?
session_start();
?>
<html>
<head></head>
<body>
<?
$locationArray = array(
'option1' => '/ordering_system/webcast/step3ressless.php',
'option2' => '/ordering_system/webcast/step3oa.php'
);
if(isset($_REQUEST['audio'])){
if(array_key_exists($_REQUEST['audio'],$locationArray)){
$location = $locationArray[$_REQUEST['audio']];
header('Location: '.$location);
exit;
}
}
// No one submitted the audio variable.. fall through to the form
?>
<form method="post" id="step2" name="step2" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label>
<span>*Audio:</span>
<select name="audio" class="select">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
</select>
</label>
<INPUT TYPE="submit" name="submit"/>
</body>
</html>
OK, I answered my own question after hours of research. Turns out it works flawlessly with some javascript; so I'm posting the answer to my own question to help anyone else who might come to these crossroads.
<script type="text/javascript">
function PostMultiple()
{
if(document.step2.audio[0].selected == true) {
document.step2.action = 'http://gohere.html';
}
if(document.step2.audio[1].selected == true) {
document.step2.action = 'http://gothere.html';
document.myform.method = 'get';
}
return true;
}
</script>
精彩评论