Jump to content


Photo

Conditional form action

form action

  • Please log in to reply
2 replies to this topic

#1 pratuljena

pratuljena

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 25 June 2013 - 08:35 AM

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

 

<html>
<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>
  </select>
 <br>
  <br>
   <br>
   
<input type="submit" value=" Show Report ">
</form>
 

Please help me on this

 

 

Thanks

Pratul



#2 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 922 posts
  • LocationVoorheesville NY

Posted 25 June 2013 - 08:40 AM

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")
$url='platform.php';
if ($checkbox_value == 'playlist')
$url = 'playlist.php';

header("Location: $url");

The last line will take you to your script.
jg

"Vote out all incumbents or nothing will ever change!"

#3 Strider64

Strider64

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationA burb of Detroit, MI

Posted 25 June 2013 - 09:20 AM

reportview.php

<?php
	if (isset($_POST['submit']) && $_POST['submit'] == 'submit') {
		$redirectToPage = htmlspecialchars($_POST['report']);	//Sanitize user's input
		header("Location: " . $redirectToPage);
		exit;
	}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Reports Tutorial</title>
<style>
#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:hover,
#basic option:hover {
	background: #ccc;
}
</style>
</head>

<body>
<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>
  </select>&nbsp;&nbsp;
  <input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Edited by Strider64, 25 June 2013 - 09:23 AM.

A simple basic registration/login tutorial can be found here: http://www.jrpepp.co...en.php?page=PHP





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com