Jump to content


Conditional form action

form action

  • Please log in to reply
2 replies to this topic

#1 pratuljena

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 25 June 2013 - 01:35 PM

Hello all,

              I am very new the to php. I need help on the following problem.


I have a page say reportview.php having a combobox with three options like :platform, playlist, build And I have another three pages like reportbyplatform.php, reportbyplaylists.php and reportbybuild.php.

Now based on the option I have selected I want to call the respective php.


for example if I select platform from the combo box then my action should be reportbyplatform.php, if I select playlist from the combo box the action should be reportbyplaylists.php and so on.


code snippet


<body><h1> <p align="Justify"> <font color="blue"> JST Automation Report </font> </h1>

<form action="?">
Show report by :     

<select id='viewType'>
    <option value="platform">platform</option>
  <option value="playlists">Playlists</option>
<input type="submit" value=" Show Report ">

Please help me on this





#2 ginerjm

  • Members
  • PipPipPip
  • Handball player
  • 4,016 posts
  • LocationVoorheesville NY

Posted 25 June 2013 - 01:40 PM

When you build the first page, set action to the script doing that build. Then when the page is submitted to that script, capture the checkbox choice. If you have one, then do this:

if ($checkbox_value == "platform")
if ($checkbox_value == 'playlist')
$url = 'playlist.php';

header("Location: $url");

The last line will take you to your script.
PS - If you're posting here you should be using:
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#3 Strider64

  • Members
  • PipPipPip
  • Advanced Member
  • 247 posts
  • LocationA burb of Detroit, MI

Posted 25 June 2013 - 02:20 PM


	if (isset($_POST['submit']) && $_POST['submit'] == 'submit') {
		$redirectToPage = htmlspecialchars($_POST['report']);	//Sanitize user's input
		header("Location: " . $redirectToPage);
<meta charset="utf-8">
<title>Reports Tutorial</title>
#basic {
	background-color: #efefef;
	border: 2px solid #000;
	color: red;
	font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
	font-size: 16px;
	font-weight: bold;
	padding: 10px;
#basic option {
	background-color: #666;
	color: #fff;
	padding: 5px 5px 0;
#basic option:hover {
	background: #ccc;

<form action="reportview.php" method="post">
  <select id="basic" name="report">
    <option selected="selected" value="reportbyplatform.php">Please select your report:</option>
    <option value="reportbyplatform.php">Platform</option>
    <option value="reportbyplaylists.php">Playlist</option>
    <option value="reportbybuild.php">Build</option>
  <input type="submit" name="submit" value="submit">

Edited by Strider64, 25 June 2013 - 02:23 PM.

 http://www.pepster.com  ||  "Insanity: doing the same thing over and over again and expecting different results." - Albert Einstein 

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users