Hello all, i have a simple result to attain, but I'm new to PHP and i'm struggling figuring out how to approach this.
I need to have a form that the user fills out, and there is a section of radio buttons, and depending on the interests of the user, it will send the user to a page relevant to his interests, where there is more info on that topic. I know there is a simple conditional approach to this, but I'm struggling integrating it with the form, and the script i have to process the form and email it to the company for records. Thanks so much in advance!!!
New to PHP-Send to URL based on what Radio btn is selected
Moderator: General Moderators
Re: New to PHP-Send to URL based on what Radio btn is selected
Example form:tjphilli wrote:Hello all, i have a simple result to attain, but I'm new to PHP and i'm struggling figuring out how to approach this.
I need to have a form that the user fills out, and there is a section of radio buttons, and depending on the interests of the user, it will send the user to a page relevant to his interests, where there is more info on that topic. I know there is a simple conditional approach to this, but I'm struggling integrating it with the form, and the script i have to process the form and email it to the company for records. Thanks so much in advance!!!
Code: Select all
<form action="redirect.php" method="post">
<input type="radio" name="site" value="1" /> Google<br/>
<input type="radio" name="site" value="2" /> Yahoo<br/>
<input type="radio" name="site" value="1" /> MSN<br/>
<input type="submit" name="submit" value="Submit" />
</form>
Code: Select all
<?php
$site = $_POST['site'];
switch($site) {
case '1':
header("Location: http://www.google.com/"); exit;
case '2':
header("Location: http://www.yahoo.com/"); exit;
case '3':
header("Location: http://www.msn.com/"); exit;
}
?>
Hope this helps.
- markusn00b
- Forum Contributor
- Posts: 298
- Joined: Sat Oct 20, 2007 2:16 pm
- Location: York, England
Re: New to PHP-Send to URL based on what Radio btn is selected
I will assume you are POSTing the form data (that is, the form's method attribute is set to 'post').
You may use the header() function to redirect a user to a specific location:
Mark.
Edit: Whoops - beaten to it.
You may use the header() function to redirect a user to a specific location:
Code: Select all
<?php
// I assume $_POST['choice'] is the form data
switch ($_POST['choice']) {
case 'sports':
header("location: http://yoursportssite/
break;
case 'porn':
header("location: http://yourpornsite/
break
case 'internalsports':
header("location: /yourinternalsportssite/");
break;
}
Edit: Whoops - beaten to it.