www.webdeveloper.com
Results 1 to 3 of 3

Thread: submit form and it goes to php page

  1. #1
    Join Date
    Jun 2007
    Posts
    186

    submit form and it goes to php page

    Hello all,

    I have a basic form with 2 drop down boxes. One drop down box allows you to choose the year (e.g. 2007, 2008, 2009) and the other drop down box allows you to choose the month (e.g. 01, 02, 03, etc). The form, when the submit button is pressed, will go to a php url. I would like to make it so that the url is determined by the chosen month and year in the drop down boxes. For instance, if I choose 2008 for year and 09 for month, I woul dlike it to go to the following url when you press the submit button:

    http://www.something.com/index.php?year=2008&month=09

    The year and month parameters in the url above would be determined by what is chosen in the 2 drop down boxes.

    Any help would be greatly appreciated.

    Thanks,
    cedric

  2. #2
    Join Date
    Jun 2007
    Posts
    186
    This is the code I have for the form:

    Code:
    <form method="POST" action="index.php">
      <p align="center"><b><font size="2" face="Verdana">Year: </font></b><font face="Verdana"><b> 
        <select size="1" name="yeardrop">
          <? 
    
    $todaysyear=date("Y");
    
    
    for($i=2007;$i<=$todaysyear;$i++)   {
    
    if($i==$year)   {
    echo "<option selected>$i</option>";
    }
    else  {
    echo "<option>$i</option>";
    }
    
    }
    
    
      ?>
        </select>
        <b><font size="2" face="Verdana"> &nbsp;&nbsp;Month: </font></b> 
        <select size="1" name="monthdrop">
          <? 
    
    $todaysyear=date("Y");
    
    
    for($i=1;$i<=12;$i++)   {
    
    
    if($i<=9)  {
    $k='0'.$i;
    }
    else  {
    $k=$i;
    }
    
    
    
    if($k==$month)   {
    echo "<option selected>$k</option>";
    }
    else  {
    echo "<option>$k</option>";
    }
    
    }
    ?>
        </select>
        </b></font><b><font size="2" face="Verdana">&nbsp;&nbsp; </font></b><font face="Verdana"><b> 
        <input type="submit" value="Go" name="B1">
        </b></font></p>
    </form>
    All the php stuff in the form is just to tell the page which years and months to put in each drop down box...as far as i know.

  3. #3
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    14
    Hi Cedric813. If you change your form's method attribute to "get", the action address will automatically change to this when you submit your form: "index.php?yeardrop=[selected year]&monthdrop=[selected month]". If you really want to change that to "year" and "month", just change the name attributes of your select elements. Wonderfully simple, eh?
    Last edited by Kryptonian; 01-01-2009 at 03:45 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles