jones_bones
asked on
PHP Simple Script for radio buttons
Hi,
Basically I want to make a choice selection page with PHP and radio buttons. If a user selects option 1 I want to direct them to page 1, option 2 go to page 2 etc. Could anyone point me in the direction of a page that has a sample form like this. I'm not too familiar with PHP syntax so I'm having problems creating it myself.
Thanks,
D
Basically I want to make a choice selection page with PHP and radio buttons. If a user selects option 1 I want to direct them to page 1, option 2 go to page 2 etc. Could anyone point me in the direction of a page that has a sample form like this. I'm not too familiar with PHP syntax so I'm having problems creating it myself.
Thanks,
D
ASKER
Hi,
Thanks for your response. I'm just wondering is this the most effeciant way to do it though as there will be over 15 pages of questions so that will mean I will have to have 15 other php pages or can I define all of these $radionselection variables on the one page and direct all of the forms to this page?
Thanks,
D
Thanks for your response. I'm just wondering is this the most effeciant way to do it though as there will be over 15 pages of questions so that will mean I will have to have 15 other php pages or can I define all of these $radionselection variables on the one page and direct all of the forms to this page?
Thanks,
D
You can use one page for all of them, just by using the if statement ....
if ($radioselection == 1)
{
// do processing for page 1;
}
elseif ($radioselection == 2)
{
// do processing for page 2;
}
etc....
However, since (presumably) the processing will be the same whether it's one page or 15, it might be more useful to use separate php scripts and include them, just for ease of maintenance.
if ($radioselection == 1)
{
// do processing for page 1;
}
elseif ($radioselection == 2)
{
// do processing for page 2;
}
etc....
However, since (presumably) the processing will be the same whether it's one page or 15, it might be more useful to use separate php scripts and include them, just for ease of maintenance.
here is another way you can do it
<?
if(isset($_POST['go'])){
$pagetogo = $_POST['radio'];
if($pagetogo == 1){
header("Location: page1.php");
exit;
}
if($pagetogo == 2){
header("Location: page2.php");
exit;
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>page2</title>
</head>
<body>
<p>Please selct one option</p>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="radio" name="radio" id="radio" value="1" />
</label>
Go to Page 1<br />
<label>
<input type="radio" name="radio" id="radio2" value="2" />
</label>
Go to page 2
<br />
<label>
<input type="submit" name="go" id="submit" value="Submit >>" />
</label>
</form>
<p> </p>
</body>
</html>
even you do this with javascript .. .by onclick you can redirect to the desired page
ASKER
Thanks guys,
I have went with your idea syedasimmeesaq:and have put the php onto the page. For some reason it is giving me the error:
Parse error: parse error, unexpected $ in /homepages/29/d233428725/h tdocs/inve s/freewill /fwa.php on line 278
when I run it?
Thanks,
D
I have went with your idea syedasimmeesaq:and have put the php onto the page. For some reason it is giving me the error:
Parse error: parse error, unexpected $ in /homepages/29/d233428725/h
when I run it?
Thanks,
D
<?php
if(isset($_POST['go'])){
$pagetogo = $_POST['radio'];
if($pagetogo == 1){
header("Location: page1.php");
exit;
}
if($pagetogo == 2){
header("Location: page2.php");
exit;
}
?>
<html><!-- InstanceBegin template="/Templates/main_t.dwt" codeOutsideHTMLIsLocked="false" --><head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>What You See...</title>
<!-- InstanceEndEditable -->
<link href="../../register_files/style_whatyousee.css" rel="stylesheet" type="text/css">
<link type="text/css" href="../../register_files/styleprint.css" rel="stylesheet" media="print"><!--[if IE]>
<style>
a.gwbtn, a.gwbtn_ie6 {cursor:hand;}
</style>
<![endif]-->
<script type="text/javascript" language="javascript" src="../../register_files/utility.js" charset="UTF-8"></script>
<script type="text/javascript" language="javascript" src="../../register_files/popup.js" charset="UTF-8"></script><!-- Any Extra Headers Here -->
<script src="../../register_files/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "UA-289919-1";urchinTracker();</script>
<script src="../../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:1px;
top:296px;
width:772px;
height:96px;
z-index:1;
}
#login {
position:absolute;
left:715px;
top:143px;
width:142px;
height:65px;
z-index:1;
}
.style1 {color: #7297D7}
.style2 {color: #999999}
.style3 {
color: #FFFFFF;
font-size: 9px;
}
.style5 {font-size: 9px}
-->
</style>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body topmargin="0" leftmargin="0" marginwidth="0">
<table summary="major layout" style="border-style: solid; border-color: rgb(236, 236, 236); border-width: 0pt 1px 1px;" align="center" border="0" cellpadding="0" cellspacing="0" width="770">
<tbody><tr><td width="169"></td>
<td width="606"></td>
<td width="1"></td>
</tr>
<!--banner--><tr class="noprint"><td colspan="3"><table style="background: transparent url(/i/banner_bg.jpg) no-repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" cellpadding="0" cellspacing="0" height="186" width="770">
<!-- TOPLINE BANNER --><tbody><tr><td align="right" height="20" valign="top">
<table summary="" class="topline_menu" border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td><a href="http://www.whatyouseeyoucannotbe.com/about.html">about </a></td>
<td bgcolor="#565656" width="1"><img src="../../register_files/spacer.gif" width="1"></td>
<td><a href="http://www.whatyouseeyoucannotbe.com/feedback.php">contact </a></td>
<td bgcolor="#565656" width="1"><img src="../../register_files/spacer.gif" width="1"></td>
<td>
<a href="http://www.whatyouseeyoucannotbe.com/feedback.php">feedback</a></td>
</tr></tbody></table></td></tr>
<!-- SECONDLINE BANNER --><tr>
</tr>
<!-- THIRD LINE --><tr>
<td align="left"><table summary="" style="background: transparent url(/i/banner_login.jpg) no-repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" class="banner_login_inset" cellpadding="0" cellspacing="0" height="0" width="0">
<tbody><tr></tr>
</tbody></table>
<table width="766">
<tr>
<td width="758" height="56"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','761','height','50','src','images/wys_nav','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/wys_nav' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="764" height="50">
<param name="movie" value="../../images/wys_nav.swf">
<param name="quality" value="high">
<embed src="../../images/wys_nav.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="764" height="50"></embed>
</object></noscript></td>
</tr>
</table>
<table width="767" height="71">
<tr>
<td height="65"><img src="../../register_files/register_new_2.png" width="766" height="124"></td>
</tr>
</table></td></tr>
</tbody></table></td></tr><!-- END OF BANNER -->
<tr>
<td height="10"><img src="../../register_files/spacer.gif" alt=""></td>
</tr>
<tr>
<!-- LEFT HAND COLUMN --><td align="center" valign="top">
<!-- MENU -->
<div class="noprint" style="margin: 0pt; padding: 0pt;"><!-- dont' print these ads -->
<table summary="" class="lhs_box" cellpadding="0" cellspacing="0"><tbody><tr><td>
<table width="143"" cellspacing="0" class="lhs_box_hdr" cellpadding=" summary=""0>
<tbody><tr><td width="138"><div align="center" class="style3">INVESTIGATIONS</div></td>
</tr></tbody></table>
<table summary="" class="lhs_box_body" cellpadding="0" cellspacing="0">
<tbody><tr><td style="font-size: 10px;">
<div class="faqlink">
Do We Really Have Free Will ?</div>
<div class="faqlink">
What The Hell Am I?</div>
<div class="faqlink">
Whats At The Centre ?</div>
<div class="faqlink">
What is Time and Space ?</div>
</td></tr></tbody></table>
</td></tr>
</tbody></table>
<table summary="" class="lhs_box" cellpadding="0" cellspacing="0"><tbody><tr><td>
<table summary="Menu" class="lhs_box_hdr" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="142"> <div align="center"><span class="style5">LINKS</span></div></td>
</tr></tbody></table>
<table summary="Menu" class="section_menu_body" cellpadding="0" cellspacing="0">
<tbody><tr>
<td class="current">
<a href="http://www.whatyouseeyoucannotbe.com">Interesting Excerpts </a></td>
</tr>
<tr>
<td class="">
<a href="http://www.whatyouseeyoucannotbe.com">Papers</a></td>
</tr>
<tr>
<td class="">
<p><a href="http://www.whatyouseeyoucannotbe.com">Fun Stuff </a></p>
</td></tr>
</tbody></table></td></tr>
</tbody></table>
<table summary="" class="lhs_box" cellpadding="0" cellspacing="0"><tbody><tr><td>
<table summary="" class="lhs_box_hdr" cellpadding="0" cellspacing="0">
<tbody><tr><td width="142" valign="middle"><div align="center" class="style5"> FAVOURITE TEACHERS </div></td>
</tr></tbody></table>
<table summary="" class="lhs_box_body" cellpadding="0" cellspacing="0">
<tbody><tr>
<td style="font-size: 10px;"> Here is a list of some of my favourite teachers
<br>
<div align="right"><a href="http://www.whatyouseeyoucannotbe.com/teacher.html" class="grey_arrow_link">read more <img src="../../register_files/grey_arrow.gif" alt=">>" border="0"></a></div>
</td></tr></tbody></table>
</td></tr>
<tr><td style="background: transparent url(../../register_files/lhs_box_footer.gif) repeat scroll 0%; height: 3px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><img src="../../register_files/spacer.gif" alt=""></td></tr>
</tbody></table>
</div> <!-- noprint -->
</td><!-- LEFT HAND COLUMN ENDS -->
<!-- MAIN AREA --><td valign="top"><span>
<!-- Page Body Here -->
<!-- InstanceBeginEditable name="Main Body" -->
<table class="mainbox" border="0" cellpadding="0" cellspacing="0" width="596">
<tbody><tr><td width="596" height="22" class="header" style="background: transparent url(../../register_files/h1_bg_extend.gif) no-repeat scroll 0px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<h1 align="center">WELCOME</h1>
</td></tr>
<tr><td height="211" class="body">
<!-- BODY GOES HERE -->
<h1>TEST:</h1>
<p> </p>
<p>Please select one option</p>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="radio" name="radio" id="radio" value="1" />
</label>
Go to Page 1<br />
<label>
<input type="radio" name="radio" id="radio2" value="2" />
</label>
Go to page 2
<br />
<label>
<input type="submit" name="go" id="submit" value="Submit >>" />
</label>
</form>
<p> </p>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr><td style="padding-left:0px">
</td></tr>
</table>
<!-- end of main box --></td></tr>
<tr><td><div class="dwb"><div class="dwbl"><div class="dwbr"><img src="../../register_files/spacer.gif" alt="" height="5"></div></div></div></td></tr>
</tbody></table>
<!-- End of Page Body --><!-- PAGE AREA ENDS-->
<!-- InstanceEndEditable -->
</tr>
<tr class="noprint"><td height="4"><img src="../../register_files/spacer.gif" alt=""></td></tr>
<tr class="noprint"><td colspan="3"><!-- FOOTER -->
<table summary="" align="center" cellpadding="0" cellspacing="0" width="720"><tbody><tr><td><table summary="" class="footer_menu" border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td><a href="http://www.whatyouseeyoucannotbe.com/about.html">about </a></td>
<td bgcolor="#565656" width="1"><img src="../../register_files/spacer.gif" width="1"></td>
<td><a href="http://www.whatyouseeyoucannotbe.com/feedback.php">contact </a></td>
<td bgcolor="#565656" width="1"><img src="../../register_files/spacer.gif" width="1"></td>
<td><a href="http://www.whatyouseeyoucannotbe.com/feedback.php">feedback </a></td>
</tr></tbody></table></td>
<td align="centre">
<img src="../../register_files/bottom_flowers_now2.png" alt="What You See..." width="190" height="55"></td>
<td align="right"><span class="style2">whatyouseeyoucannotbe© Copyright 2008 </span></td>
</tr></tbody></table>
</td>
</tr>
</tbody></table>
<!-- END OF MAJOR LAYOUT -->
<div id="popup" style="visibility: hidden; position: absolute; left: 200px; width: 500px; top: 100px;">
<table bgcolor="#6e7ad7" border="1" cellpadding="3" cellspacing="0" width="100%">
<tbody><tr><td width="100%">
<table border="0" cellpadding="0" cellspacing="0" height="36" width="100%">
<tbody><tr><td id="titleBar" height="20" width="100%">
<layer width="100%">
<font color="#ffffff" face="Verdana"><b><div id="popupTitle">Popup Title</div></b></font>
</layer></td>
<td style="" valign="top">
<a href="#" onClick="popupClose('close');return false">
<font style="text-decoration: none;" color="#ffffff" size="2"><b>X</b></font></a>
</td></tr>
<tr>
<td style="padding: 1px;" colspan="2" bgcolor="#999999" width="100%">
<table bgcolor2="#d9ebf7" align="center" bgcolor="#ffffff" border="0" cellpadding="0" width="100%">
<tbody><tr><td valign="top"><div id="popupBody">
The body of the popup
</div>
</td></tr></tbody></table>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<center class="noprint">
<a href="http://www.newaddress.ie/" style="color: #999999;"></a>
</center>
</body><!-- InstanceEnd --></html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent! Thanks all for your help
Glad to be of help
God bless you
God bless you
<form ..... action="radiobuttonpage.ph
<input name= radiobutton type=radio value=1 .....>
</form>
Then in radiobuttonpage.php, just check which radio button was selected and include the page for that button.
$radioselection = $_POST["radiobutton"];
if ($radioselection ==1 )
include "page1.php";
elseif ($radioselection ==2)
include "page2.php";
else .....