#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Php calendar and drop down box values


    Hi I'm new to php and i have a calendar which has a link for each day so when u click a day on the calendar the values appear on another page (hook.php). How ever what i want is when you click a day on the calendar it is highlighted and you can choose a value from a drop down box. When you choose your date and option box value, the values appear on the next page. So if you chose the 1st of February 2013 then choose Spain from the drop down box these values will appear on the next page. Here is my code. Any help would be greatly appreciated. Thanks

    Code:
    <?php
    $monthNames = Array("January", "February", "March", "April", "May", "June", "July", 
    "August", "September", "October", "November", "December");
    ?>
    <?php
    $cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : date("n");
    $cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
     
    $prev_year = $cYear;
    $next_year = $cYear;
    $prev_month = $cMonth-1;
    $next_month = $cMonth+1;
     
    if ($prev_month == 0 ) {
        $prev_month = 12;
        $prev_year = $cYear - 1;
    }
    if ($next_month == 13 ) {
        $next_month = 1;
        $next_year = $cYear + 1;
    }
    ?><!DOCTYPE html>
     <html>
     <head>
     <title>Hook Up</title>
     </head>
     <style type="text/css">
    	table {
    		border: 1px solid black;
    		border-collapse: collapse;
    	}
    	th {
    		border: 1px solid black;
    		padding: 6px;
    		font-weight: bold;
    		background: #ccc;
    	}
    	td {
    		border: 1px solid black;
    		padding: 6px;
    		vertical-align: top;
    		width: 100px;
    		}
    </style>
    <script type="text/javascript">
    function eventWindow(url) {
    		event_popupWin = window.open(url, 'event',
    		'resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
    		event_popupWin.opener = self;
    }
    </script>
    <body>
    <h1>Select a Night Out</h1>
    <table width="200">
    <tr align="center">
    <td bgcolor="#999999" style="color:#FFFFFF">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
    <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>  </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center">
    <table width="100%" border="0" cellpadding="2" cellspacing="2">
    <tr align="center">
    <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
    </tr>
    <tr>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
    </tr>
    <?php 
    $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
    $maxday = date("t",$timestamp);
    $thismonth = getdate ($timestamp);
    $startday = $thismonth['wday'];
    $today = date('j');
    $currentmonth = date('n');
    for ($i=0; $i<($maxday+$startday); $i++) {
    if(($i % 7) == 0 ){
    echo "<tr>";
    }
    if($i < $startday){
    echo ("<td class='cell cell_txt'> </td>");
    } else {
    if (($i - $startday + 1) == $today && $currentmonth == $cMonth){
    echo ("<td class='cell_today cell_txt'>".($i-$startday+ 1)."</td>");
    } else {
    echo ("<td class='cell cell_txt'><a href=\"hook.php?day=".($i - $startday + 1)."&amp;month=".$cMonth."&amp;year=".$cYear."\">".($i - $startday + 1)."</a></td>");
    }
    }
    if(($i % 7) == 6 ) {
    echo "</tr>\n";
    }
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    </body>
    	</html>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    1) Please edit your post and use [ PHP ] tags rather than [ CODE ] tags. See the sticky at the top of this forum.
    2) In order to do what you want you need to create a form and "Submit" the data to hook.php which then has access to the selection in the drop down box (along with any other form data) and display the next page accordingly.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Hi I'm new to php and i have a calendar which has a link for each day so when u click a day on the calendar the values appear on another page (hook.php). How ever what i want is when you click a day on the calendar it is highlighted and you can choose a value from a drop down box. When you choose your date and option box value, the values appear on the next page. So if you chose the 1st of February 2013 then choose Spain from the drop down box these values will appear on the next page. Here is my code. Any help would be greatly appreciated. Thanks

    PHP Code:
    <?php
    $monthNames 
    = Array("January""February""March""April""May""June""July"
    "August""September""October""November""December");
    ?>
    <?php
    $cMonth 
    = isset($_REQUEST["month"]) ? $_REQUEST["month"] : date("n");
    $cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
     
    $prev_year $cYear;
    $next_year $cYear;
    $prev_month $cMonth-1;
    $next_month $cMonth+1;
     
    if (
    $prev_month == ) {
        
    $prev_month 12;
        
    $prev_year $cYear 1;
    }
    if (
    $next_month == 13 ) {
        
    $next_month 1;
        
    $next_year $cYear 1;
    }
    ?>
    <!DOCTYPE html>
     <html>
     <head>
     <title>Hook Up</title>
     </head>
     <style type="text/css">
        table {
            border: 1px solid black;
            border-collapse: collapse;
        }
        th {
            border: 1px solid black;
            padding: 6px;
            font-weight: bold;
            background: #ccc;
        }
        td {
            border: 1px solid black;
            padding: 6px;
            vertical-align: top;
            width: 100px;
            }
    </style>
    <script type="text/javascript">
    function eventWindow(url) {
            event_popupWin = window.open(url, 'event',
            'resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
            event_popupWin.opener = self;
    }
    </script>
    <body>
    <h1>Select a Night Out</h1>
    <table width="200">
    <tr align="center">
    <td bgcolor="#999999" style="color:#FFFFFF">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month="$prev_month "&year=" $prev_year?>" style="color:#FFFFFF">Previous</a></td>
    <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month="$next_month "&year=" $next_year?>" style="color:#FFFFFF">Next</a>  </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center">
    <table width="100%" border="0" cellpadding="2" cellspacing="2">
    <tr align="center">
    <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear?></strong></td>
    </tr>
    <tr>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
    </tr>
    <?php 
    $timestamp 
    mktime(0,0,0,$cMonth,1,$cYear);
    $maxday date("t",$timestamp);
    $thismonth getdate ($timestamp);
    $startday $thismonth['wday'];
    $today date('j');
    $currentmonth date('n');
    for (
    $i=0$i<($maxday+$startday); $i++) {
    if((
    $i 7) == ){
    echo 
    "<tr>";
    }
    if(
    $i $startday){
    echo (
    "<td class='cell cell_txt'> </td>");
    } else {
    if ((
    $i $startday 1) == $today && $currentmonth == $cMonth){
    echo (
    "<td class='cell_today cell_txt'>".($i-$startday1)."</td>");
    } else {
    echo (
    "<td class='cell cell_txt'><a href=\"hook.php?day=".($i $startday 1)."&month=".$cMonth."&year=".$cYear."\">".($i $startday 1)."</a></td>");
    }
    }
    if((
    $i 7) == ) {
    echo 
    "</tr>\n";
    }
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    </body>
        </html>
    This is my hook.php page
    Code:
    <table width="90%" align="center" cellpadding="6">
            <tr>
              <td style="line-height:1.7em;"><h2>Selected Dates<br />            
              </h2><?php
    echo "<br/> Year: ".$_GET['year'];
    echo "<br/> Month: ".$_GET['month'];
    echo "<br/> Day: ".$_GET['day'];
    echo "<br/> Date: ".$_GET['day'].$_GET['month'].$_GET['year'];
    
    ?></td>
            </tr>
          </table></td>
    This is the options i need but i don't know how to put them all together to get the values onto the hook.php page under the same button
    PHP Code:
                 <table width="100%" border="0" align="center">
                    <tr>
                      <td width="34%">
                      <select name="county" class="formFields">
                        <option value="<?php print "$county"?>"><?php print "$county"?></option>
                        <option value="Cork">Cork</option>
                        <option value="Antrim">Antrim</option>
                        <option value="Armagh">Armagh</option>
                        <option value="Carlow">Carlow</option>
                        <option value="Cavan">Cavan</option>
                        <option value="Clare">Clare</option>
                        <option value="Derry">Derry</option>
                        <option value="Donegal">Donegal</option>
                        <option value="Down">Down</option>
                        <option value="Dublin">Dublin</option>
                        <option value="Fermanagh">Fermanagh</option>
                        <option value="Galway">Galway</option>
                        <option value="Kerry">Kerry</option>
                        <option value="Kildare">Kildare</option>
                        <option value="Kilkenny">Kilkenny</option>
                        <option value="Laois">Laois</option>
                        <option value="Leitrim">Leitrim</option>
                        <option value="Limerick">Limerick</option>
                        <option value="Longford">Longford</option>
                        <option value="Louth">Louth</option>
                        <option value="Mayo">Mayo</option>
                        <option value="Meath">Meath</option>
                        <option value="Monaghan">Monaghan</option>
                        <option value="Offaly">Offaly</option>
                        <option value="Roscommon">Roscommon</option>
                        <option value="Sligo">Sligo</option>
                        <option value="Tipperary">Tipperary</option>
                        <option value="Tyrone">Tyrone</option>
                        <option value="Waterford">Waterford</option>
                        <option value="Westmeath">Westmeath</option>
                        <option value="Wexford">Wexford</option>
                        <option value="Wicklow">Wicklow</option>
                      </select></td>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    Where is the <form> tag? That is where you tell the browser to pass the data to hook.php.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    I have been using this line:

    PHP Code:
    echo ("<td class='cell cell_txt'><a href=\"hook.php?day=".($i $startday 1)."&month=".$cMonth."&year=".$cYear."\">".($i $startday 1)."</a></td>"); 
    Its down near the end of the first lot of php code?? Not sure if what i am doing is right
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    OK, so you are not using a form. The variable in the URL can be obtained with the PHP global array $_GET.
    PHP Code:
    $day=$_GET['day'];
    $month=$_GET['month'];
    $year=$_GET['year']; 
    You'll need to add your dropdown selection to the URL but you get it the same way.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    No but would it be better for me to use a form?? This is what i have been working with so i just presumed this was the best way?? Thanks
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    I'd say yes. Using $_POST rather than $_GET give you more flexibility in passing data to your script and makes it a little more difficult for hackers to tamper with the data.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    I don'teven know where to start to try and change to doing that. Im a scared if i mess around with it i will just ruin it
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    form tag tip


    If you are worried about making irreversible mistakes, make copies, often...

    Google: html form w3schools
    I can't post links

    Basically every variable you want to send to another page you need to encapsulate in a form tag.

    e.g.
    PHP Code:
    <form name="calendarSubmit" id="calendarSubmit" action="hook.php" method="GET">
      <
    select name="county" class="formFields"
        <
    option value="Cork">Cork</option>
        <!--  
    The rest of your options... -->
      </
    select>
      <
    input type="submit" value="Submit" />
    </
    form
    The only thing is getting your date values across since there are 3 values being selected at once on your link.

    One thing you could do is have 3 hidden values like this:

    PHP Code:
    <input type="hidden" name="day" id="day" value="0">
    <
    input type="hidden" name="month" id="month" value="">
    <
    input type="hidden" name="year" id="year" value="0"
    ^Inside your form tags of course and have a javascript function to set the values when your links are clicked instead of going to the page, or have it submit after the values are set.

    PHP Code:
    <script type="text/javascript">
    function 
    setValues(selectedDayselectedMonthselectedYear)
    {
      var 
    daydocument.getElementById("day");
      var 
    monthdocument.getElementById("month");
      var 
    yeardocument.getElementById("year");

      
    day.value selectedDay;
      
    month.value selectedMonth;
      
    year.value selectedYear;

      
    document.forms["calendarSubmit"].submit();
    }
    </script> 
    and your links would now be something like this:

    PHP Code:
    echo ("<td class='cell cell_txt'><a href=\"#\" onClick=\"setValues('".($i $startday 1)."', '".$cMonth."', '".$cYear."');\">".($i $startday 1)."</a></td>"); 
    NOTE: I put single quote around all values being sent there, same may be numbers and don't require quotes.

    So your final form will be like:

    PHP Code:
    <form name="calendarSubmit" id="calendarSubmit" action="hook.php" method="GET">
      <
    input type="hidden" name="day" id="day" value="">
      <
    input type="hidden" name="month" id="month" value="">
      <
    input type="hidden" name="year" id="year" value="">

      <
    select name="county" class="formFields"
        <
    option value="Cork">Cork</option>
        <!--  
    The rest of your options... -->
      </
    select>
    </
    form
    Then add that javascript function and exchange your link line for mine.

    Let me know how it goes Goodluck
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Thanks a million khayhurst, I'l get started on this straight away
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Hi, I have gotten this to work. At the moment i can choose a county from a drop down box and then when i click a date on the calendar it shows these values on the hook.php page. I was just wondering if there was a way to choose the county from the drop down box, then select the date from the calendar and click a button like "submit". So you would choose a county, highlight a date from the calendar and click the submit button and be shown your values on the hook.php page. Here is my code so far, I hope its right. Sorry for being so annoying I am just struggling with this at the moment.


    PHP Code:
    <?php
    $monthNames 
    = Array("January""February""March""April""May""June""July"
    "August""September""October""November""December");
    ?>
    <?php
    $cMonth 
    = isset($_REQUEST["month"]) ? $_REQUEST["month"] : date("n");
    $cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
     
    $prev_year $cYear;
    $next_year $cYear;
    $prev_month $cMonth-1;
    $next_month $cMonth+1;
     
    if (
    $prev_month == ) {
        
    $prev_month 12;
        
    $prev_year $cYear 1;
    }
    if (
    $next_month == 13 ) {
        
    $next_month 1;
        
    $next_year $cYear 1;
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <script type="text/javascript"> 
    function setValues(selectedDay, selectedMonth, selectedYear) 

      var day= document.getElementById("day"); 
      var month= document.getElementById("month"); 
      var year= document.getElementById("year"); 

      day.value = selectedDay; 
      month.value = selectedMonth; 
      year.value = selectedYear; 

      document.forms["calendarSubmit"].submit(); 

    </script> 
    <body>


    <table class="mainBodyTable" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
    <h1>Select a Night Out</h1> 
    <table width="200"> 
    <tr align="center"> 
    <td bgcolor="#999999" style="color:#FFFFFF"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month="$prev_month "&year=" $prev_year?>" style="color:#FFFFFF">Previous</a></td> 
    <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month="$next_month "&year=" $next_year?>" style="color:#FFFFFF">Next</a>  </td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    <tr> 
    <td align="center"> 
    <table width="100%" border="0" cellpadding="2" cellspacing="2"> 
    <tr align="center"> 
    <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear?></strong></td> 
    </tr> 
    <tr> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> 
    </tr> 
    <form name="calendarSubmit" id="calendarSubmit" action="hook.php" method="GET"> 
      <input type="hidden" name="day" id="day" value=""> 
      <input type="hidden" name="month" id="month" value=""> 
      <input type="hidden" name="year" id="year" value=""> 

      <select name="county" class="formFields">  
        <option value="Cork">Cork</option> 
        <!--  The rest of your options... --> 
      </select> 
    </form> 
    <?php 
    $timestamp 
    mktime(0,0,0,$cMonth,1,$cYear);
    $maxday date("t",$timestamp);
    $thismonth getdate ($timestamp);
    $startday $thismonth['wday'];
    $today date('j');
    $currentmonth date('n');
    for (
    $i=0$i<($maxday+$startday); $i++) {
    if((
    $i 7) == ){
    echo 
    "<tr>";
    }
    if(
    $i $startday){
    echo (
    "<td class='cell cell_txt'> </td>");
    } else {
    if ((
    $i $startday 1) == $today && $currentmonth == $cMonth){
    echo (
    "<td class='cell_today cell_txt'>".($i-$startday1)."</td>"); 
    } else {
    echo (
    "<td class='cell cell_txt'><a href=\"#\" onClick=\"setValues('".($i $startday 1)."', '".$cMonth."', '".$cYear."');\">".($i $startday 1)."</a></td>");  

    }
    if((
    $i 7) == ) {
    echo 
    "</tr>\n";
    }
    }
    ?>
    </table>
    </td>
    </tr>

    </table>
    </body>
    </html>
    Heres my hook.php code
    PHP Code:
          <table width="90%" align="center" cellpadding="6">
            <tr>
              <td style="line-height:1.7em;"><h2>Selected Dates<br />            
              </h2><?php
    echo "<br/> Year: ".$_GET['year'];
    echo 
    "<br/> Month: ".$_GET['month'];
    echo 
    "<br/> Day: ".$_GET['day'];
    echo 
    "<br/> Date: ".$_GET['day'].$_GET['month'].$_GET['year'];
    echo 
    "<br/> County: ".$_GET['county'];
    ?></td>
            </tr>
          </table></td>
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    No problem


    rats, how do you delete a post
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    No problem


    To stop the form from submitting simply remove this line

    PHP Code:
    document.forms["calendarSubmit"].submit(); 
    and add a submit button to the bottom of the form

    PHP Code:
    <input type="submit" value="Submit" /> 
    Hope you get it working!

IMN logo majestic logo threadwatch logo seochat tools logo