Calendar Woes With Form Variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ClanKeithROoF
    New Member
    • Sep 2008
    • 2

    Calendar Woes With Form Variables

    I'm working on a calendar that works well in all points except one. I found the code online and modified it to fit my needs. One of my mods isn't working. I'm trying to make it display the chosen month under the drop down box but I'm getting and "Element MONTH_VAL is undefined in FORM" error. It seems to be defined to me but I could be missing something obvious. I'm using cfif's to look for form.month_val which is an integer and then display the month based on which month has been chosen. That's where the error is. I've noted the section that's erroring out in the comments.

    I would appreciate any help. Thanks much.

    Code:
    <cfoutput>
    <div align="center"><h2>#DateFormat(now(), "mmmm, d, yyyy")#</h2></div>
    </cfoutput>
    </p>
    
    <form name="cal_select" method="get" action="#CGI.script_name#">   
       <div align="center">To view the events of a particular month:<br />Select Month Number - Enter Year - Click "Go"</div>
       <p align="center">
    
    <p align="center">
    <input type="submit" name="Go" value="GO" />
    <cfoutput>
    <select name="month_val">
    	<option>#month(now())#</option>
    	<option>1</option>
    	<option>2</option>
    	<option>3</option>
    	<option>4</option>
    	<option>5</option>
    	<option>6</option>
    	<option>7</option>
    	<option>8</option>
    	<option>9</option>
    	<option>10</option>
    	<option>11</option>
    	<option>12</option>
    </select>
    </cfoutput>
    <cfoutput>
    <input name="year_val" value="#year(now())#" />
    </cfoutput>
    <cfoutput>
    
    </cfoutput>
    <cfoutput>
    </p></form>
    
    <!---Display the selected month--THIS IS WERE THE ERROR IS OCCURING--->
    <p>
    <div align="center">
    <cfif isDefined(form.month_val)>
    	<cfif form.month_val EQ 1>
    	January
    	<cfelseif form.month_val EQ 2>
    	February
    	<cfelseif form.month_val EQ 3>
    	March
    	<cfelseif form.month_val EQ 4>
    	April
    	<cfelseif form.month_val EQ 5>
    	May
    	<cfelseif form.month_val EQ 6>
    	June
    	<cfelseif form.month_val EQ 7>
    	July
    	<cfelseif form.month_val EQ 8>
    	August
    	<cfelseif form.month_val EQ 9>
    	September
    	<cfelseif form.month_val EQ 10>
    	October
    	<cfelseif form.month_val EQ 11>
    	November
    	<cfelseif form.month_val EQ 12>
    	December
    	</cfif>
    </cfif>
    </div>
    </p>
    <!---/Display the selected month -- END ERROR SECTION--->
    
    
    <form name="caltest1" method="post">
    
    <table border="1" width="100%">
    <tr>
    <cfloop index="x" from="1" to="7">
    <th><span class="style2 style4">#dayOfWeekAsString(x)#</span></th>
    </cfloop>
    </tr>
    </cfoutput>
    
    <cfparam name="year_val" type="integer" default="#DatePart('yyyy', Now())#">
    <cfparam name="month_val" type="integer" default="#DatePart('m', Now())#">
    
    <cfset firstOfTheMonth = CreateDate(#year_val#, #month_val#, 1)>
    <cfset dow = dayofWeek(firstOfTheMonth)>
    <cfset pad = dow - 1>
    
    <cfoutput>
    <tr>
    </cfoutput>
    
    <cfif pad gt 0>
    <cfoutput><td colspan="#pad#">&nbsp;</td></cfoutput>
    </cfif>
    
    <cfset days = daysInMonth(firstOfTheMonth)>
    <cfset counter = pad + 1>
    
    <cfloop index="x" from="1" to="#days#">
    <cfif x is day(now())>
    <cfoutput><td bgcolor="yellow" width="14%"></cfoutput>
    <cfelse>
    <cfoutput><td width="14%"></cfoutput>
    </cfif>
    
    <cfset yourDate = createDate(#year_val#, #month_val#, #x#)>
    
    <cfquery name="Events" datasource="ds_eventsCalendar">
    SELECT *
    FROM tbl_events
    WHERE start_date=#CreateODBCDate(yourDate)#
    </cfquery>
    
    <cfoutput>
    <div align="center">
    <strong>#DateFormat(yourDate, "d")#</strong>
    </cfoutput>
    <p>
    <cfoutput query="Events">
    <div align="center">#desc#<br /></div>
    <p>
    </cfoutput>
    </td>
    </div>
    
    <cfset counter = counter + 1>
    <cfif counter is 8>
    <cfoutput></tr>
        
        
    </cfoutput>
    <cfif x lt days>
    <cfset counter = 1>
    <cfoutput>
    <tr>
    </cfoutput>
    </cfif>
    </cfif>
    </cfloop>
    
    <cfif counter is not 8>
    <cfset endPad = 8 - counter>
    <cfoutput>
    <td colspan="#endPad#">&nbsp;</td>
    
    </tr>
    </cfoutput>
    </cfif>
    
    <cfoutput>
    </table>
    </cfoutput>
    <cfoutput>
    <!---<input name="date" value="#DateFormat(yourDate, "mmmm, d, yyyy")#" />--->
    </cfoutput>
    </form>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Put "form.month_val " in quotes in isDefined(). You could also use cfparam to give form variables default values. There's some code that could be improved, but we can deal with that later.

    Comment

    • ClanKeithROoF
      New Member
      • Sep 2008
      • 2

      #3
      Param's turned out to be the answer. Here is the correctly working calendar:

      Code:
      <div id="calHolder">
      <p>
      <cfoutput>
      <div align="center"><h3>#DateFormat(now(), "mmmm, d, yyyy")#</h3></div>
      </cfoutput>
      </p>
      <form name="cal_select" method="get" action="#CGI.script_name#">   
      <div align="center">To view the events of a particular month:<br />Select Month Number - Select Year - Click "Go"</div>
      <p align="center">
      
      <p align="center">
      <cfoutput>
      Month: <select name="month_val">
      	<option></option>
      	<option>1</option>
      	<option>2</option>
      	<option>3</option>
      	<option>4</option>
      	<option>5</option>
      	<option>6</option>
      	<option>7</option>
      	<option>8</option>
      	<option>9</option>
      	<option>10</option>
      	<option>11</option>
      	<option>12</option>
      </select>
      <!---<input name="month_val" value="#month(now())#" />--->
      </cfoutput>
      <cfoutput>
      Year: <select name="year_val">
      	<option></option>
      	<option>2008</option>
      	<option>2009</option>
      	<option>2010</option>
      	<option>2011</option>
      	<option>2012</option>
      	<option>2013</option>
      	<option>2014</option>
      	<option>2015</option>
      </select>
      <!---<input name="year_val" value="#year(now())#" />--->
      </cfoutput>
       <input type="submit" name="Go" value="GO" />
      <cfoutput>
      </p>
      </form>
      <!--- +++++++++++++++++++++++++++ --->
      <!---
      THIS WAS THE PROBLEM SECTION 
      THE PARAM'S FIXED THE PROBLEM
      --->
      <!--- +++++++++++++++++++++++++++ --->
      <cfparam name="month_val" type="integer" default="#DatePart('m', Now())#">
      <cfparam name="year_val" type="integer" default="#DatePart('yyyy', Now())#">
      <cfset monthTitle = #month_val#>
      <cfset yearTitle = #year_val#>
      <!---Display the selected month and year--->
      <p>
      <div align="center" id="calSelectedYM">
      	<cfif monthTitle EQ 1>
      	January
      	<cfelseif monthTitle EQ 2>
      	February
      	<cfelseif monthTitle EQ 3>
      	March
      	<cfelseif monthTitle EQ 4>
      	April
      	<cfelseif monthTitle EQ 5>
      	May
      	<cfelseif monthTitle EQ 6>
      	June
      	<cfelseif monthTitle EQ 7>
      	July
      	<cfelseif monthTitle EQ 8>
      	August
      	<cfelseif monthTitle EQ 9>
      	September
      	<cfelseif monthTitle EQ 10>
      	October
      	<cfelseif monthTitle EQ 11>
      	November
      	<cfelseif monthTitle EQ 12>
      	December
      	</cfif>
      	<cfif yearTitle EQ 2008>
      	 2008
      	<cfelseif yearTitle EQ 2009>
      	 2009
      	<cfelseif yearTitle EQ 2010>
      	 2010
      	<cfelseif yearTitle EQ 2011>
      	 2011
      	<cfelseif yearTitle EQ 2012>
      	 2012
      	<cfelseif yearTitle EQ 2013>
      	 2013
      	<cfelseif yearTitle EQ 2014>
      	 2014
      	<cfelseif yearTitle EQ 2015>
      	 2015
      	</cfif>
      </div><!--/calSelectedYM-->
      </p>
      <!---/END PROBLEM SECTION--->
      <!---/Display the selected month and year--->
      <form name="caltest1" method="post">
      <table border="1" width="100%">
      <tr>
      <cfloop index="x" from="1" to="7">
      <th><span class="style2 style4">#dayOfWeekAsString(x)#</span></th>
      </cfloop>
      </tr>
      </cfoutput>
      
      <cfparam name="year_val" type="integer" default="#DatePart('yyyy', Now())#">
      <cfparam name="month_val" type="integer" default="#DatePart('m', Now())#">
      
      <cfset firstOfTheMonth = CreateDate(#year_val#, #month_val#, 1)>
      <cfset dow = dayofWeek(firstOfTheMonth)>
      <cfset pad = dow - 1>
      
      <cfoutput>
      <tr>
      </cfoutput>
      
      <cfif pad gt 0>
      <cfoutput><td colspan="#pad#">&nbsp;</td></cfoutput>
      </cfif>
      
      <cfset days = daysInMonth(firstOfTheMonth)>
      <cfset counter = pad + 1>
      
      <cfloop index="x" from="1" to="#days#">
      <cfif x is day(now())>
      <cfoutput><td width="14%"></cfoutput>
      <cfelse>
      <cfoutput><td width="14%"></cfoutput>
      </cfif>
      
      <cfset yourDate = createDate(#year_val#, #month_val#, #x#)>
      
      <cfquery name="Events" datasource="ds_pattern">
      SELECT *
      FROM tbl_events
      WHERE start_date=#CreateODBCDate(yourDate)#
      </cfquery>
      
      <cfoutput>
      <div align="center">
      <strong>#DateFormat(yourDate, "d")#</strong>
      </cfoutput>
      <p>
      <cfoutput query="Events">
      <div align="center">#descr#<br /></div>
      <p>
      </cfoutput>
      </td>
      </div>
      
      <cfset counter = counter + 1>
      <cfif counter is 8>
      <cfoutput></tr>
          
      </cfoutput>
      <cfif x lt days>
      <cfset counter = 1>
      <cfoutput>
      <tr>
      </cfoutput>
      </cfif>
      </cfif>
      </cfloop>
      
      <cfif counter is not 8>
      <cfset endPad = 8 - counter>
      <cfoutput>
      <td colspan="#endPad#">&nbsp;</td>
      
      </tr>
      </cfoutput>
      </cfif>
      
      <cfoutput>
      </table>
      </cfoutput>
      </form>
      </div><!--/calHolder-->

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Pleased to see that it's working, though the displaying of the month and year code looks terribly inefficient. Rather than those if statements, just display the value using cfoutput. For the month, set the option values to the name of the month.

        Comment

        Working...