Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 135,912 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,559 people online right now. Registration is fast and FREE... Join Now!




Directing results from multiple drop down menus

 
Reply to this topicStart new topic

Directing results from multiple drop down menus

Lydon
22 May, 2008 - 05:30 AM
Post #1

New D.I.C Head
*

Joined: 22 May, 2008
Posts: 8


My Contributions
Hi all

First time asking for help in a forum as i normally like to figure things out myself but after not having used php for over a year, i'm a bit stuck with what i'm trying to do and hoping some kind soul is able to point me in the right direction...

In the nutshell, I have a web form which has two drop down menus among other things. What i want to be able to do is make it so that depending on what options are chosen from the drop downs, after clicking submit the user is presented with a URL where a file is available for download. There are numerous files each uniquely dependant on the options chosen in the drop down menu.

For example..

CODE

<td align="left"><select name="matriculation" id="matriculation_year">
                      <option value="2007">2007</option>
                      <option value="2006">2006</option>
                      <option value="2005">2005</option>
                      </select>

is a few of the options available in the first drop down menu.


CODE

<td align="left"><select name="common_room" id="common_room_affiliation">
                      <option value="JCR">JCR</option>
                      <option value="MCR">MCR</option>
                    </select>

is the entire second drop down menu (which is NOT dependant on what option is chosen in the first drop down).

SO, what i would like to do is offer a certain URL should the user choose 2005 and JCR, and offer a different URL should the user choose 2007 MCR etc.

The code i have so far to try and sort this out is:

CODE

<?php
if(isset($_POST['post']))
{
       if (($_POST['matriculation'] == '2007') AND ($_POST['common_room'] == 'MCR'))
{
       header("Location: https://whatever.com");
}
elseif (($_POST['matriculation'] == '2006') AND ($_POST['common_room'] == 'MCR'))
{
       header("Location: https://somewhere_else.com");
}
else { die("Error"); }
exit;
}
?>


Unfortunately, as it is so long since i used PHP, i'm not even sure i'm going along the right track with this one. The form action is a new page where it shows the same form and it *should* offer the correct URL underneath the form, but at the moment it is doing nothing at all except showing the HTML code making up the form. No matter what i try i cannot get a URL displayed sad.gif
Any help you could offer would be greatly appreciated.

Many thanks

User is offlineProfile CardPM
+Quote Post

joeyadms
RE: Directing Results From Multiple Drop Down Menus
22 May, 2008 - 08:05 AM
Post #2

D.I.C Head
Group Icon

Joined: 4 May, 2008
Posts: 145



Thanked: 6 times
Dream Kudos: 600
Expert In: PHP, Web Security

My Contributions
Definately Use a Switch, and use concatenation to make it easier, or at least my 2 cents. something like this
CODE

$fileOptions = $_POST['matriculation'] . "_" . $_POST['common_room'];

switch($fileOptions) {
case '2007_MCR':
          //header location blah
          break;
case '2006_MCR':
         //header location blah
         break;
//more cases
default:
      //set error message, send to options page

}


Hope that helps out.
User is offlineProfile CardPM
+Quote Post

Lydon
RE: Directing Results From Multiple Drop Down Menus
27 May, 2008 - 01:59 AM
Post #3

New D.I.C Head
*

Joined: 22 May, 2008
Posts: 8


My Contributions
Sorry, been away for a few days...that switch looks great, i would never have thought of it. Can i just ask though, will it go in the same page as the form and be checked after clicking the submit button, or will it be on a second page which is called in the 'action=new_page.php' part of the form?

Cheers

This post has been edited by Lydon: 27 May, 2008 - 02:02 AM
User is offlineProfile CardPM
+Quote Post

joeyadms
RE: Directing Results From Multiple Drop Down Menus
27 May, 2008 - 05:38 AM
Post #4

D.I.C Head
Group Icon

Joined: 4 May, 2008
Posts: 145



Thanked: 6 times
Dream Kudos: 600
Expert In: PHP, Web Security

My Contributions
You can put it on a different page, or you can just leave action='' and just check to see if your post variables exist, if they do , then you can assume the form was submitted, like this.
CODE

<?php

if($_POST['matriculation'] && $_POST['common_room']){
    // Form has been submitted

    $fileOptions = $_POST['matriculation'] . "_" . $_POST['common_room'];
    switch($fileOptions) {
    case '2007_MCR':
              //header location blah
              break;
    case '2006_MCR':
             //header location blah
             break;
    //more cases
    default:
          //set error message, send to options page
    
    }

}

//Show form

User is offlineProfile CardPM
+Quote Post

Lydon
RE: Directing Results From Multiple Drop Down Menus
27 May, 2008 - 07:20 AM
Post #5

New D.I.C Head
*

Joined: 22 May, 2008
Posts: 8


My Contributions
Many thanks for that, worked a treat biggrin.gif

Cheers!
User is offlineProfile CardPM
+Quote Post

Lydon
RE: Directing Results From Multiple Drop Down Menus
3 Jun, 2008 - 07:40 AM
Post #6

New D.I.C Head
*

Joined: 22 May, 2008
Posts: 8


My Contributions
'ello, me again.

I've had to add a bit of verification to this code which checks to see if an email address the user enters is part of a certain domain. If it is, then they are allowed to go ahead with the re-direct contained in the all the switch cases.
If the email address does *not* end in what it is supposed to, a message needs displayed telling them which domain to use.

I managed to get this working but the way i've done it is obviosuly wrong, as it keeps displaying the error message right from the start, before any information is entered in the form, so i've tried a couple of new ways using cookies and sessions but this is all new terretory to me, so i'd appreciate any help...


This is my first attempt:
CODE

$email = $_POST['email'];
$rest =substr($email,-13,13);

if ($rest == "example.co.uk" && $_POST['matriculation'] && $_POST['common_room'])
{
      // Form has been submitted
     $fileOptions = $_POST['matriculation'] . "_" . $_POST['common_room'];
     switch($fileOptions)

    same as code from earlier post which works...

    else if (!$rest == "example.co.uk")
   {
    echo "Enter your correct email address please";
   }    

which worked, but as i say, it ALWAYS displays the "Enter your correct email please"


Looking over my second (and third) attempt, i've not actually managed to get anything of any use apart from:
CODE

session_start();
session_register('rest','email');


which actually may not be of any use at all. As i say, never used sessions before and what i looked up on the web just seemed to show how you should write code to display how many times you have looked at a certain web page :s. Not much use to me at all...

Anyhoo, please help biggrin.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:46AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month