Hey all!
Im trying to integrate a simple event calander into my phpbb forums that adds events to current and upcoming weeks in a database. The form I use has a text box for an event name with a submit button and two select menus:
1. a list of (upcoming) event weeks (running Sat through Fri) populated from a database where people have actually submitted an availability sometime in that week.
2. A list of specific days to select.
The php file calls itself from the a .tpl file handling the form and checks if the Post Method was used. The idea here is the first visit to the page defaults to the current week and the current day. If another week or day is selected and an event name is submitted, then the event is created in a database.
The database lookups are all correct and I can actually choose a new week from the week select menu and a different day from the day select menu and successfully add an event into the events database on the correct week/day.
The problem is the select boxes always revert back to the initial current week and today's day (Monday, Tue, etc...) instead of keeping the selected values from the form...even though I repopulate the array sent back to the form template with the values selected.
Any idea why it wont repopulate the form with the new selected data?
Here is the php code snippet:
Code:
if ($_SERVER['REQUEST_METHOD'] != 'POST')
{
$today = getdate();
if($today['wday'] == 6)
{
$week= time();
}
else{
$week= strtotime("last Saturday", time());
}
$day= date('D',time());
$daylong = date('l',time());
$sql = "SELECT DISTINCT`week` FROM `e_avail` WHERE `week` >= '$week' ORDER BY `week`";
if ( !($result=$db->sql_query($sql)))
{}
while( $row = $db->sql_fetchrow($result) )
{
$start = date('n/j/Y',$row['week']);
$end = date('n/j/Y',(strtotime("+6 days",$row['week'])));
$weekstr = '<option value="'.$row['week'].'">'.$start.' through '.$end.'</option>';
$template->assign_block_vars('menu_weeks',array( 'R_MENUWEEK' => $weekstr));
}
$db->sql_freeresult($result);
$selectstr='<option SELECTED value="'.time().'">'.$daylong.'</option>';
$template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $selectstr));
for($n =1; $n <=6; $n +=1)
{
$nextday = time() +($n*24*60*60);
$longday = date('l',$nextday);
$daystr = '<option value="'.$nextday.'">'.$longday.'</option>';
$template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $daystr));
}
}
else
{
$week=$_POST['week'];
$day= date('D',$_POST['day']);
$longday = date('l',$POST['day']);
$event=$_POST['event'];
$sql = "SELECT DISTINCT `week` FROM `e_avail` WHERE `week` >= '$week' ORDER BY `week`";
if ( !($result=$db->sql_query($sql)))
{}
while( $row = $db->sql_fetchrow($result) )
{
$start = date('n/j/Y',$row['week']);
$end = date('n/j/Y',(strtotime("+6 days",$row['week'])));
$weekstr = '<option value="'.$row['week'].'">'.$start.' through '.$end.'</option>';
$template->assign_block_vars('menu_weeks',array( 'R_MENUWEEK' => $weekstr));
}
$db->sql_freeresult($result);
$selectstr='<option SELECTED value="'.$_POST['day'].'">'.$longday.'</option>';
$template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $selectstr));
for($n =1; $n <=6; $n +=1)
{
$nextday = $POST['day'] +($n*24*60*60);
$longday = date('l',$nextday);
$daystr = '<option value="'.$nextday.'">'.$longday.'</option>';
$template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $daystr));
}
if(!($_POST['event']==''))
{
$sql = "INSERT INTO " . _events . "(week,day,event_name) VALUES ('$week','$day','$event')";
if (!$db->sql_query($sql))
}
}
...and the actual form code in the template.
Code:
<table width="860">
<form method="post" action="events.php" >
<tr><td><br />
<b>Week: </b>
<select name="week" style="background-color:#FFFFFF; color:#000000">
<!-- BEGIN menu_weeks -->
{menu_weeks.R_MENUWEEK}
<!-- END menu_weeks -->
</select>
<br />Day: </b>
<select name="day" style="background-color: #FFFFFF;color:#000000" >
<!-- BEGIN menu_days -->
{menu_days.R_MENUDAY}
<!-- END menu_days -->
</select>
<br />Create Event:</b>
<input type=text name="event" style="background-color: #FFFFFF;color:#000000" size=20>
<input type=submit style="background-color: #FFFFFF;color:#000000" value="Create Event">
</form>
</td>
</tr>
</table>
Thanks in advance!