Jump to content

Dropdown Selection open different page


Scooby-Doo

Recommended Posts

I am struggling again, right do my best to explain got a dropdown with 3 selections..ie

 

<form action="prices.php" method="post" name="prices">
<select name="dropdowns" class="selectionbox" value="options" id="selection">
        <option value="ns" selected="selected">Please Select</option>
        <option value="selection1.php">Selection 1</option>
        <option value="selection2.php">Selection 2</option>
        <option value="selection3.php">Selection 3</option>
        </select>

 

When the user clicks on the "Get Prices" button it will open prices.php....but on prices.php I want to have an include("selection1.php") or (selection2.php) etc depending on what the user selected in the drop down box.

 

Now dont laugh at my code but I have done this but dont know how to make it just chose one at the minute it is just including both of them

 

 

<?php $selection1 = isset($_POST['selection1']) ? $_POST["selection1"] : "";
$selection2 = isset($_POST['selection2']) ? $_POST["selection2"] : "";
if ($selection1);
include ("selection1.php"); 
if ($selection2); 
include ("selection2.php"); 
?>

 

Any help much appreciated...and as you can probably see im new to php

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/263144-dropdown-selection-open-different-page/
Share on other sites

Not sure if this will help.

<html>
<body>
<?php
isset($_POST['dropdowns']) ? include($_POST["dropdowns"]) : "";
?>
<form action="prices.php" method="post" name="prices">
<select name="dropdowns" class="selectionbox" value="options" id="selection">
        <option value="ns" selected="selected">Please Select</option>
        <option value="selection1.php">Selection 1</option>
        <option value="selection2.php">Selection 2</option>
        <option value="selection3.php">Selection 3</option>
        </select>
	<input type="submit" value="Submit" />
	</form>
</body>
</html>

Sorry, but I have to advise against using Drummin's solution. You should never use values from user submitted data directly in an include statement. You need to validate it first.

 

$includeValue = isset($_POST['dropdowns']) ? $_POST['dropdowns'] : false;

switch($includeValue)
{
    case 'selection1.php':
    case 'selection2.php':
    case 'selection3.php':
        include($includeValue);
        break;

    default:
        include('selection1.php');
}

Thank you Psycho worked a treat....Just one more question, I have used your code so it includes() the selected pages..ie

 


$inspection = isset($_POST['inspections']) ? $_POST['inspections'] : false;
$delivery = isset($_POST['delivery']) ? $_POST['delivery'] : false; 
switch($inspection)
{
    case 'basic.php':
    case 'platinum.php':
    case 'accident.php':
        include($inspection);
        break;

    default:
        include('basic.php');
}
?>
<?php
switch($delivery)
{
    case 'delivery.php':
    case 'nodelivery.php':
        include($delivery);
        break;

    default:
        include('nodelivery.php');
}
?>

 

Would it be difficult to put a value to each selection...for arguments sake if someone selected Platinum Inspection £10 with no delivery £0 it would calculate the two prices and place in a total inspection + delivery

 

Hope that makes sense

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.