Submit button & functions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ir0nSpIkE
Forum Newbie
Posts: 7
Joined: Mon May 16, 2005 4:25 pm
Location: On the Island, BC Canada

Submit button & functions?

Post by Ir0nSpIkE »

I've created a functions that creates a Month dropdown that is pre-populated with the current month + x. Something like:

Code: Select all

function MonthDropDown($size=90,$default="DropDate") 
{  $skip=1;
   echo "<select name=$default STYLE=\"font-family: monospace;\">\n";
   for ($i = 0; $i <= $size; $i++) 
   {  $theMonth = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y"));
      $option=date("D M j, Y",$theday);
      ...  
   }
   echo "</select>\n";
   return  date("m/d/Y",$theMonth);
}
At the moment I have 3 functions for month day & year. I concatinate the results into the date format I want. My problem is how to use this date as input to a submit button to another page. Or am I going up a tree using this approach?

Jcart | Please use

Code: Select all

tags when posting php code.  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post by SBro »

Put the date into a session and then retrieve it on the next page ie.

Code: Select all

session_start();

function MonthDropDown($size=90,$default="DropDate") 
{  $skip=1;
   echo "<select name=$default STYLE=\"font-family: monospace;\">\n";
   for ($i = 0; $i <= $size; $i++) 
   {  $theMonth = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y"));
      $option=date("D M j, Y",$theday);
      ...  
   }
   echo "</select>\n";
   return  date("m/d/Y",$theMonth);
}

$_SESSION['date'] = MonthDropDown();
Then on the next page where you want to put it into a input field:

Code: Select all

&lt;?php session_start(); ?&gt;
&lt;input type=&quote;Submit&quote; name=&quote;Date&quote; value=&quote;&lt;?=$_SESSION&#1111;'date'];?&gt;&quote;&gt;
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

or you could use JS and do it all on one page...
Post Reply