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
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>

Link to comment
Share on other sites

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');
}

Link to comment
Share on other sites

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

 

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.