Skip to main content
Known Participant
Aug 15, 2013 11:58 AM UTC
Answered

Check form input against a list of data

Hi all,

I apologize in advance if I don't use the proper terminology here.  What I'm trying to do is rather simple, I think, but it's not something I've done before.  I have a short list of dates in a DB table.  Upon a user inputting a date into a form field and submitting it, I would like CF to check the date the user entered against the list of dates in the table.  I'd like to be able to create a cfif/cfelse statement if the input date matches any one of the table dates. Can someone point me in the right direction?

Thanks!

    This topic is closed to new replies. Start a new post to keep the conversation going.
    p_sim
    p_simCorrect answer
    Participating Frequently
    Aug 15, 2013 2:18 PM UTC

    Oh, sorry I misunderstood.

    "upon form submission" -- Then in the action page, you create a query against the submitted date.

    WHERE date_column = <cfqueryparam value="#form.submittedDate#" cfsqltype="cf_sql_date">

    The if statement looks like this:

    <!--- if record found --->

    <cfif queryName.recordCount>

         Insert response 1

    <cfelse>

         insert response 2

    </cfif>

    4 replies

    p_sim
    Participating Frequently
    Aug 15, 2013 12:59 PM UTC

    Use AJAX and jQuery. The way it works is similar to:

    http://jacktraynor.blogspot.com/2012/02/jquery-autocomplete-using-coldfusion.html

    Translate
    straffenpAuthor
    Known Participant
    Aug 15, 2013 1:07 PM UTC

    Thanks, p.sim.  I'm not sure if what I'm trying to do is that complicated, however the example you provided will be helpful for other projects.

    Basically, upon form submission, I want CF to query my db table of dates and if one of those dates matches the date the user selected from a drop down in the form, CF will insert one of two text responses.  So something like,

    <cfif #form.VisitDate# eq any of the dates in #query.OpenDate#>Insert response 1<cfelse>insert response 2</cfif>

    Maybe I'm missing something or overthinking it...

    Thanks again!

    Translate
    p_sim
    p_simCorrect answer
    Participating Frequently
    Aug 15, 2013 2:18 PM UTC

    Oh, sorry I misunderstood.

    "upon form submission" -- Then in the action page, you create a query against the submitted date.

    WHERE date_column = <cfqueryparam value="#form.submittedDate#" cfsqltype="cf_sql_date">

    The if statement looks like this:

    <!--- if record found --->

    <cfif queryName.recordCount>

         Insert response 1

    <cfelse>

         insert response 2

    </cfif>

    Translate