Connecting Tech Pros Worldwide Forums | Help | Site Map

Calendar Woes With Form Variables

Newbie
 
Join Date: Sep 2008
Posts: 2
#1: Sep 23 '08
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.

Expand|Select|Wrap|Line Numbers
  1. <cfoutput>
  2. <div align="center"><h2>#DateFormat(now(), "mmmm, d, yyyy")#</h2></div>
  3. </cfoutput>
  4. </p>
  5.  
  6. <form name="cal_select" method="get" action="#CGI.script_name#">   
  7.    <div align="center">To view the events of a particular month:<br />Select Month Number - Enter Year - Click "Go"</div>
  8.    <p align="center">
  9.  
  10. <p align="center">
  11. <input type="submit" name="Go" value="GO" />
  12. <cfoutput>
  13. <select name="month_val">
  14.     <option>#month(now())#</option>
  15.     <option>1</option>
  16.     <option>2</option>
  17.     <option>3</option>
  18.     <option>4</option>
  19.     <option>5</option>
  20.     <option>6</option>
  21.     <option>7</option>
  22.     <option>8</option>
  23.     <option>9</option>
  24.     <option>10</option>
  25.     <option>11</option>
  26.     <option>12</option>
  27. </select>
  28. </cfoutput>
  29. <cfoutput>
  30. <input name="year_val" value="#year(now())#" />
  31. </cfoutput>
  32. <cfoutput>
  33.  
  34. </cfoutput>
  35. <cfoutput>
  36. </p></form>
  37.  
  38. <!---Display the selected month--THIS IS WERE THE ERROR IS OCCURING--->
  39. <p>
  40. <div align="center">
  41. <cfif isDefined(form.month_val)>
  42.     <cfif form.month_val EQ 1>
  43.     January
  44.     <cfelseif form.month_val EQ 2>
  45.     February
  46.     <cfelseif form.month_val EQ 3>
  47.     March
  48.     <cfelseif form.month_val EQ 4>
  49.     April
  50.     <cfelseif form.month_val EQ 5>
  51.     May
  52.     <cfelseif form.month_val EQ 6>
  53.     June
  54.     <cfelseif form.month_val EQ 7>
  55.     July
  56.     <cfelseif form.month_val EQ 8>
  57.     August
  58.     <cfelseif form.month_val EQ 9>
  59.     September
  60.     <cfelseif form.month_val EQ 10>
  61.     October
  62.     <cfelseif form.month_val EQ 11>
  63.     November
  64.     <cfelseif form.month_val EQ 12>
  65.     December
  66.     </cfif>
  67. </cfif>
  68. </div>
  69. </p>
  70. <!---/Display the selected month -- END ERROR SECTION--->
  71.  
  72.  
  73. <form name="caltest1" method="post">
  74.  
  75. <table border="1" width="100%">
  76. <tr>
  77. <cfloop index="x" from="1" to="7">
  78. <th><span class="style2 style4">#dayOfWeekAsString(x)#</span></th>
  79. </cfloop>
  80. </tr>
  81. </cfoutput>
  82.  
  83. <cfparam name="year_val" type="integer" default="#DatePart('yyyy', Now())#">
  84. <cfparam name="month_val" type="integer" default="#DatePart('m', Now())#">
  85.  
  86. <cfset firstOfTheMonth = CreateDate(#year_val#, #month_val#, 1)>
  87. <cfset dow = dayofWeek(firstOfTheMonth)>
  88. <cfset pad = dow - 1>
  89.  
  90. <cfoutput>
  91. <tr>
  92. </cfoutput>
  93.  
  94. <cfif pad gt 0>
  95. <cfoutput><td colspan="#pad#">&nbsp;</td></cfoutput>
  96. </cfif>
  97.  
  98. <cfset days = daysInMonth(firstOfTheMonth)>
  99. <cfset counter = pad + 1>
  100.  
  101. <cfloop index="x" from="1" to="#days#">
  102. <cfif x is day(now())>
  103. <cfoutput><td bgcolor="yellow" width="14%"></cfoutput>
  104. <cfelse>
  105. <cfoutput><td width="14%"></cfoutput>
  106. </cfif>
  107.  
  108. <cfset yourDate = createDate(#year_val#, #month_val#, #x#)>
  109.  
  110. <cfquery name="Events" datasource="ds_eventsCalendar">
  111. SELECT *
  112. FROM tbl_events
  113. WHERE start_date=#CreateODBCDate(yourDate)#
  114. </cfquery>
  115.  
  116. <cfoutput>
  117. <div align="center">
  118. <strong>#DateFormat(yourDate, "d")#</strong>
  119. </cfoutput>
  120. <p>
  121. <cfoutput query="Events">
  122. <div align="center">#desc#<br /></div>
  123. <p>
  124. </cfoutput>
  125. </td>
  126. </div>
  127.  
  128. <cfset counter = counter + 1>
  129. <cfif counter is 8>
  130. <cfoutput></tr>
  131.  
  132.  
  133. </cfoutput>
  134. <cfif x lt days>
  135. <cfset counter = 1>
  136. <cfoutput>
  137. <tr>
  138. </cfoutput>
  139. </cfif>
  140. </cfif>
  141. </cfloop>
  142.  
  143. <cfif counter is not 8>
  144. <cfset endPad = 8 - counter>
  145. <cfoutput>
  146. <td colspan="#endPad#">&nbsp;</td>
  147.  
  148. </tr>
  149. </cfoutput>
  150. </cfif>
  151.  
  152. <cfoutput>
  153. </table>
  154. </cfoutput>
  155. <cfoutput>
  156. <!---<input name="date" value="#DateFormat(yourDate, "mmmm, d, yyyy")#" />--->
  157. </cfoutput>
  158. </form>
  159.  

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 24 '08

re: Calendar Woes With Form Variables


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.
Newbie
 
Join Date: Sep 2008
Posts: 2
#3: Sep 24 '08

re: Calendar Woes With Form Variables


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

Expand|Select|Wrap|Line Numbers
  1. <div id="calHolder">
  2. <p>
  3. <cfoutput>
  4. <div align="center"><h3>#DateFormat(now(), "mmmm, d, yyyy")#</h3></div>
  5. </cfoutput>
  6. </p>
  7. <form name="cal_select" method="get" action="#CGI.script_name#">   
  8. <div align="center">To view the events of a particular month:<br />Select Month Number - Select Year - Click "Go"</div>
  9. <p align="center">
  10.  
  11. <p align="center">
  12. <cfoutput>
  13. Month: <select name="month_val">
  14.     <option></option>
  15.     <option>1</option>
  16.     <option>2</option>
  17.     <option>3</option>
  18.     <option>4</option>
  19.     <option>5</option>
  20.     <option>6</option>
  21.     <option>7</option>
  22.     <option>8</option>
  23.     <option>9</option>
  24.     <option>10</option>
  25.     <option>11</option>
  26.     <option>12</option>
  27. </select>
  28. <!---<input name="month_val" value="#month(now())#" />--->
  29. </cfoutput>
  30. <cfoutput>
  31. Year: <select name="year_val">
  32.     <option></option>
  33.     <option>2008</option>
  34.     <option>2009</option>
  35.     <option>2010</option>
  36.     <option>2011</option>
  37.     <option>2012</option>
  38.     <option>2013</option>
  39.     <option>2014</option>
  40.     <option>2015</option>
  41. </select>
  42. <!---<input name="year_val" value="#year(now())#" />--->
  43. </cfoutput>
  44.  <input type="submit" name="Go" value="GO" />
  45. <cfoutput>
  46. </p>
  47. </form>
  48. <!--- +++++++++++++++++++++++++++ --->
  49. <!---
  50. THIS WAS THE PROBLEM SECTION 
  51. THE PARAM'S FIXED THE PROBLEM
  52. --->
  53. <!--- +++++++++++++++++++++++++++ --->
  54. <cfparam name="month_val" type="integer" default="#DatePart('m', Now())#">
  55. <cfparam name="year_val" type="integer" default="#DatePart('yyyy', Now())#">
  56. <cfset monthTitle = #month_val#>
  57. <cfset yearTitle = #year_val#>
  58. <!---Display the selected month and year--->
  59. <p>
  60. <div align="center" id="calSelectedYM">
  61.     <cfif monthTitle EQ 1>
  62.     January
  63.     <cfelseif monthTitle EQ 2>
  64.     February
  65.     <cfelseif monthTitle EQ 3>
  66.     March
  67.     <cfelseif monthTitle EQ 4>
  68.     April
  69.     <cfelseif monthTitle EQ 5>
  70.     May
  71.     <cfelseif monthTitle EQ 6>
  72.     June
  73.     <cfelseif monthTitle EQ 7>
  74.     July
  75.     <cfelseif monthTitle EQ 8>
  76.     August
  77.     <cfelseif monthTitle EQ 9>
  78.     September
  79.     <cfelseif monthTitle EQ 10>
  80.     October
  81.     <cfelseif monthTitle EQ 11>
  82.     November
  83.     <cfelseif monthTitle EQ 12>
  84.     December
  85.     </cfif>
  86.     <cfif yearTitle EQ 2008>
  87.      2008
  88.     <cfelseif yearTitle EQ 2009>
  89.      2009
  90.     <cfelseif yearTitle EQ 2010>
  91.      2010
  92.     <cfelseif yearTitle EQ 2011>
  93.      2011
  94.     <cfelseif yearTitle EQ 2012>
  95.      2012
  96.     <cfelseif yearTitle EQ 2013>
  97.      2013
  98.     <cfelseif yearTitle EQ 2014>
  99.      2014
  100.     <cfelseif yearTitle EQ 2015>
  101.      2015
  102.     </cfif>
  103. </div><!--/calSelectedYM-->
  104. </p>
  105. <!---/END PROBLEM SECTION--->
  106. <!---/Display the selected month and year--->
  107. <form name="caltest1" method="post">
  108. <table border="1" width="100%">
  109. <tr>
  110. <cfloop index="x" from="1" to="7">
  111. <th><span class="style2 style4">#dayOfWeekAsString(x)#</span></th>
  112. </cfloop>
  113. </tr>
  114. </cfoutput>
  115.  
  116. <cfparam name="year_val" type="integer" default="#DatePart('yyyy', Now())#">
  117. <cfparam name="month_val" type="integer" default="#DatePart('m', Now())#">
  118.  
  119. <cfset firstOfTheMonth = CreateDate(#year_val#, #month_val#, 1)>
  120. <cfset dow = dayofWeek(firstOfTheMonth)>
  121. <cfset pad = dow - 1>
  122.  
  123. <cfoutput>
  124. <tr>
  125. </cfoutput>
  126.  
  127. <cfif pad gt 0>
  128. <cfoutput><td colspan="#pad#">&nbsp;</td></cfoutput>
  129. </cfif>
  130.  
  131. <cfset days = daysInMonth(firstOfTheMonth)>
  132. <cfset counter = pad + 1>
  133.  
  134. <cfloop index="x" from="1" to="#days#">
  135. <cfif x is day(now())>
  136. <cfoutput><td width="14%"></cfoutput>
  137. <cfelse>
  138. <cfoutput><td width="14%"></cfoutput>
  139. </cfif>
  140.  
  141. <cfset yourDate = createDate(#year_val#, #month_val#, #x#)>
  142.  
  143. <cfquery name="Events" datasource="ds_pattern">
  144. SELECT *
  145. FROM tbl_events
  146. WHERE start_date=#CreateODBCDate(yourDate)#
  147. </cfquery>
  148.  
  149. <cfoutput>
  150. <div align="center">
  151. <strong>#DateFormat(yourDate, "d")#</strong>
  152. </cfoutput>
  153. <p>
  154. <cfoutput query="Events">
  155. <div align="center">#descr#<br /></div>
  156. <p>
  157. </cfoutput>
  158. </td>
  159. </div>
  160.  
  161. <cfset counter = counter + 1>
  162. <cfif counter is 8>
  163. <cfoutput></tr>
  164.  
  165. </cfoutput>
  166. <cfif x lt days>
  167. <cfset counter = 1>
  168. <cfoutput>
  169. <tr>
  170. </cfoutput>
  171. </cfif>
  172. </cfif>
  173. </cfloop>
  174.  
  175. <cfif counter is not 8>
  176. <cfset endPad = 8 - counter>
  177. <cfoutput>
  178. <td colspan="#endPad#">&nbsp;</td>
  179.  
  180. </tr>
  181. </cfoutput>
  182. </cfif>
  183.  
  184. <cfoutput>
  185. </table>
  186. </cfoutput>
  187. </form>
  188. </div><!--/calHolder-->
  189.  
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Sep 25 '08

re: Calendar Woes With Form Variables


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.
Reply


Similar ColdFusion bytes