SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Launching a script based on radio button response

    I'm trying to create a form with radio buttons that will launch a specific script when the user hits the Go button. I know I can use <?php echo $_SERVER['PHP_SELF']; ?> to launch the current script, so I was thinking I could use <?php echo $_SERVER['sample.php']; ?> to launch the "sample.php" script. Here's an example of what I thinking (but it doesn't work!).

    Any suggestions? Please!

    Code HTML4Strict:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="admin" method="get">
    <fieldset><legend>Select an option, then click Go</legend>
    <ol>
    <li>
    <input id="option1" name="option" class="checkbox" type="radio" value="1" />
    <label for="option1">Add a new sermon</label>
    </li>
    <li>
    <input id="option2" name="option" class="checkbox" type="radio" value="1" />
    <label for="option2">Add a new speaker</label>
    </li>
    <li>
    <input id="option3" name="option"element class="checkbox" type="radio" value="1" />
    <label for="option3">Modify a speaker name</label>
    </li>
    </ol>
    </fieldset> 
    <fieldset class="submit"> 
    <input class="submit" type="submit" name="submit" value="Go" />  
    </fieldset> 
    </form>
     
    <?php if (isset($_POST['submit']))  // Handle the form.
    {
      if ($_POST["option1"])
        {$_SERVER['admin/sample1.php'];}
     
      if ($_POST["option2"])
        {$_SERVER['admin/sample2.php'];}
     
      if ($_POST["option3"])
        {$_SERVER['admin/sample3.php'];}
    }
    ?>

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($_POST["option1"])
        {
    header("Location:admin/sample1.php");}
     
    if (
    $_POST["option2"])
        {
    header("Location:admin/sample2.php");}
     
    if (
    $_POST["option3"])
        {
    header("Location:admin/sample3.php");} 
    Just a suggestion , create a form handler page.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick response. I'll try that.

    What do you mean by "form handler page"? do you have sample?

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Send that form data to a script "page_handler.php" or something like that. You do not have to generate a header or body (you will never see this page) just write your script to get your post values and process accordingly. You can then use the header function to go back to the page you came from or on to another page.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


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
  •