Skip to main content
Participant
February 17, 2012
Answered

Checking an Array with a form input field to return true or false?

  • February 17, 2012
  • 1 reply
  • 647 views

I have an array that when dumped, lists dates for all days of the month. There is a form, where the user specifies the date and when submitted, transfers to a processing.cfm file which is where i want the <cfif> to check if the date specified in form exists in the array (this way, it only limits the user of only being able to select a date from this month for an event). Is it possible to have a cfif where it will check whether or not the array contains the date the user has specified and the return true (if contains the date specified), and transfers the form to email.cfm (where it will email all the form inputs) or will return false (if outside that range) then return back to the eventform.cfm?

    This topic has been closed for replies.
    Correct answer BobbyWales21

    Nevermind. Figured it out.

    Heres my code if it will help anyone:

    <!---CFSET's--->

                    <cfset theDate = Now()>

                    <cfset NextMonth = DateAdd('m', 1, theDate) />

                    <cfset nextMonthNum = daysInMonth(#NextMonth#) />

                    <cfset weekNum = (#weekOfMonth(now())#) />

                    <cfset daysNum = daysInMonth(now()) />

                    <cfset dateToday = Now()>

                   

                    <cfscript>

                                                      function weekOfMonth(thisDate) {

                                                                var thisDay=day(thisDate);

                                                                var thisWeek=0;

                                                                if (thisDay LTE 7)

                                                                thisWeek=1;

                                                                else if (thisDay GT 7 AND thisDay LTE 14)

                                                                thisWeek=2;

                                                                else if (thisDay GT 14 AND thisDay LTE 21)

                                                                thisWeek=3;

                                                                else

                                                                thisWeek=4;

                                                                return thisWeek;

                                                      }

                                            </cfscript>

                   

                    <cfset datearray = ArrayNew(1)>

                   

                    <cfif #DatePart('w', TheDate)# GTE 2 AND #weekNum# GTE 3>

                        <cfloop index="x" from="1" to="#daysNum#">

                                      <cfset datearray = "#DateFormat(now(), "mm")#/#x#/#DateFormat(now(), "yy")#" />

                                <cfset recordnumber = #x#>

                                                      </cfloop>

                        <cfloop index="y" from="1" to="#nextMonthNum#">

                                  <cfset potato = #y# + #recordnumber# >

                                      <cfset datearray[potato] = "#DateFormat(NextMonth, "mm")#/#y#/#DateFormat(NextMonth, "yy")#" >

                        </cfloop>

                                  <cfelse>

                                  <cfloop index="z" from="1" to="#daysNum#">

                                <cfset datearray = "#DateFormat(now(), "mm")#/#z#/#DateFormat(now(), "yy")#">

                                  </cfloop>

                            </cfif>

                   

                    <cfif #arrayContains( datearray, "#form.activitydate#" )#>

                              <cflocation url="monkey.cfm">

                                  <cfelse>

                                      <cfset datetrue = "no">

                                <script>

                                                                                    alert("Date Not Valid. Please Specify Event Date Within Valid Range.<br>(Allow a couple seconds to refresh)")

                                                                                    history.go(-1)

                                                                          </script>

                    </cfif>

    1 reply

    BobbyWales21AuthorCorrect answer
    Participant
    February 17, 2012

    Nevermind. Figured it out.

    Heres my code if it will help anyone:

    <!---CFSET's--->

                    <cfset theDate = Now()>

                    <cfset NextMonth = DateAdd('m', 1, theDate) />

                    <cfset nextMonthNum = daysInMonth(#NextMonth#) />

                    <cfset weekNum = (#weekOfMonth(now())#) />

                    <cfset daysNum = daysInMonth(now()) />

                    <cfset dateToday = Now()>

                   

                    <cfscript>

                                                      function weekOfMonth(thisDate) {

                                                                var thisDay=day(thisDate);

                                                                var thisWeek=0;

                                                                if (thisDay LTE 7)

                                                                thisWeek=1;

                                                                else if (thisDay GT 7 AND thisDay LTE 14)

                                                                thisWeek=2;

                                                                else if (thisDay GT 14 AND thisDay LTE 21)

                                                                thisWeek=3;

                                                                else

                                                                thisWeek=4;

                                                                return thisWeek;

                                                      }

                                            </cfscript>

                   

                    <cfset datearray = ArrayNew(1)>

                   

                    <cfif #DatePart('w', TheDate)# GTE 2 AND #weekNum# GTE 3>

                        <cfloop index="x" from="1" to="#daysNum#">

                                      <cfset datearray = "#DateFormat(now(), "mm")#/#x#/#DateFormat(now(), "yy")#" />

                                <cfset recordnumber = #x#>

                                                      </cfloop>

                        <cfloop index="y" from="1" to="#nextMonthNum#">

                                  <cfset potato = #y# + #recordnumber# >

                                      <cfset datearray[potato] = "#DateFormat(NextMonth, "mm")#/#y#/#DateFormat(NextMonth, "yy")#" >

                        </cfloop>

                                  <cfelse>

                                  <cfloop index="z" from="1" to="#daysNum#">

                                <cfset datearray = "#DateFormat(now(), "mm")#/#z#/#DateFormat(now(), "yy")#">

                                  </cfloop>

                            </cfif>

                   

                    <cfif #arrayContains( datearray, "#form.activitydate#" )#>

                              <cflocation url="monkey.cfm">

                                  <cfelse>

                                      <cfset datetrue = "no">

                                <script>

                                                                                    alert("Date Not Valid. Please Specify Event Date Within Valid Range.<br>(Allow a couple seconds to refresh)")

                                                                                    history.go(-1)

                                                                          </script>

                    </cfif>

    BKBK
    Community Expert
    Community Expert
    February 17, 2012

    Nevermind. Figured it out.

    Good for you! Then please kindly mark this as answered.