Reputation: 128
I have setup a form that allows a user to make selections from drop-down lists, and clicking the submit button will redirect them to the appropriate page based off of their selections. Here is the PHP:
<?PHP
function redirect($where){
header("Location: $where");
}
if ($_REQUEST['os1'] == 'xp' && $_REQUEST['browser'] == 'ffx'){
redirect('http://mysite.com/index.php/prodemo/prodemo-categories/73-prodemo-xp- firefox');
}elseif($_REQUEST['os1'] == 'xp' && $_REQUEST['browser'] == 'ie8'){
redirect('http://mysite.com/index.php/prodemo/prodemo-categories/72-prodemo-xp-ie');
}elseif($_REQUEST['os1'] == 'win7' && $_REQUEST['browser'] == 'ie8'){
redirect('http://mysite.com/index.php/prodemo/prodemo-categories/74-prodemo-win7-ie');
}elseif($_REQUEST['os1'] == 'win7' && $_REQUEST['browser'] == 'ffx'){
redirect('http://mysite.com/index.php/prodemo/prodemo-categories/75-prodemo-win7- firefox');
}
?>
I am manually telling the query where to take the user.
My dilemma is that I want a simple line that says: "Hi, _. How can I help you?"
The blank would be filled in by the name that is inputted on the form as the Caller's name. Here is an example of the form:
<form action="" method="post" name="form1">
Caller's Name: <input type="text" name="callersname" /><br />
<select name="os1"> <option selected="selected" value="xp">XP</option>
<option value="win7">Win7</option> </select> <br />
<select name="browser"> <option selected="selected" value="ie8">IE8</option>
<option value="ffx">Firefox</option></select> <br />
<input type="submit" value="Next" />
I'm very new to PHP. If I create a PHP page to post the caller's name, then how do I avoid the page redirecting to that php page instead of the redirect I have manually setup with the drop-down menu options selected?
Thanks for any advixce
Upvotes: 0
Views: 524
Reputation: 1405
If you want to store the user's name on a page other than the first page or the same page that is processing the form values (IE the script that's getting the redirect) you want to store that information either in a database, or more simply in a session.
First, initialize the session on each page where you need to pull that information from:
session_start();
Then, create a session variable (unique to every user/browser) like so:
$_SESSION['user_name'] = $_REQUEST['callersname'];
Now, on the page you wish to retrieve their name (IE Hi ) just do so like this:
echo "Hi {$_SESSION['callersname']} welcome to mcdonalds how may I help you?";
Upvotes: 2
Reputation: 2223
Try using $_POST
instead of $_REQUEST
... It may be the problem and too, add action="yourpage.php"
to tell the code to send the form to the current page or another page...
Upvotes: 0
Reputation: 1838
In HTML a form will submit to the url that is given in the value of the action attribute of the form tag. In your example above you have:
action=""
This tells the browser to submit the form to the current page.
It sounds like you are trying to do two somewhat unrelated things in the same step. Are you trying to get the caller's name or have them choose what url to go to? If you want to do both, you may be better off by just accepting the os1 and browser values as POST variables, and dynamically changing the page based on the value of those variables rather than redirecting the user to entirely separate pages.
Upvotes: 0