Jump to content

Conditional form action


pratuljena

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>  
  <input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Edited by Strider64
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.