SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select box that goes to a new page within site

    Hi all,

    This should be pretty basic stuff, but coding the forms can be a bit
    above me sometimes I've hunted around and can't seem to find the
    answer, so here goes...

    I've got a select box, with a bunch of options that need to go to
    another page in the website when the go button is clicked. I'm running
    this on my localhost (using IP address 192.168.0.50), so not sure if the CGI scripts are all there, I am running PHP though, so it would be ideal to set it up that way.

    Here is my code, would appreciate any links/advice. Cheers


    <form action="post" action="http://192.168.0.50/includes/redirect.php" name="selectCourse" id="selectCourseForm">
    <fieldset>
    <select name="newURL">
    <option>Select a course</option>
    <option value="http://192.168.0.50/courses/artsAndMedia.php">Arts &amp; Media</option>
    <option value="http://192.168.0.50/courses/businessAndPublicServices.php">Business &amp; Public Services</option>
    <option value="http://192.168.0.50/courses/careTravelAndTourism.php">Care Travel &amp; Tourism</option>
    <option>ESOL &amp; Languages</option>
    <option>Hair, Beauty &amp; Sport</option>
    <option>Humanities &amp; English</option>
    <option>ICT &amp; Maths</option>
    <option>Performing Arts &amp; Media</option>
    <option>Skills for life</option>
    <option>Science</option>
    </select>
    <input name="submit" type="submit" id="goButton_replace" value="Go"/>
    </fieldset>
    </form>
    Also, here is the PHP redirect script:

    <?php
    header("Location: " . $_POST['newURL']);
    ?>

    When I submit it seems to try and add on the new URL to the existing one in the toolbar, to be honest I'm not sure if it is finding the script at all, but the location is correct.

    If you have a better way of doing this, completely different to mine, I am all ears!

    Cheers

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    this is a really bad idea because anybody could then pass any URL to your page and be redirected.

    your form should look something like this instead:
    Code:
    <form action="post" action="http://192.168.0.50/includes/redirect.php" name="selectCourse" id="selectCourseForm">
    <fieldset>
    <select name="newURL">
    <option>Select a course</option>
    <option value="am">Arts &amp; Media</option>
    <option value="bps">Business &amp; Public Services</option>
    <option value="ctt">Care Travel &amp; Tourism</option>
    <option>ESOL &amp; Languages</option>
    <option>Hair, Beauty &amp; Sport</option>
    <option>Humanities &amp; English</option>
    <option>ICT &amp; Maths</option>
    <option>Performing Arts &amp; Media</option>
    <option>Skills for life</option>
    <option>Science</option>
    </select>
    <input name="submit" type="submit" id="goButton_replace" value="Go"/>
    </fieldset>
    </form>
    and your redirect page should be like this:
    PHP Code:
    <?php
    $urls 
    = array('am'  => 'http://192.168.0.50/courses/artsAndMedia.php'
                
    'bps' => 'http://192.168.0.50/courses/businessAndPublicServices.php'
                
    'ctt' => 'http://192.168.0.50/courses/careTravelAndTourism.php');

    if (isset(
    $urls[$_POST['newURL']])) {
      
    header("Location: " $urls[$_POST['newURL']]);
    }
    ?>

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks for that, that's even better. Much appreciated...

  4. #4
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does this solution still work?
    I input it and replaced some data with mine and I get a 500 server error.

    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •