Skip to main content
Known Participant
May 7, 2007
Answered

Hidden Date

  • May 7, 2007
  • 2 replies
  • 511 views
I have a form page that I would like to attach a hidden date to when the user fills out the form. Then, when I do a CFOUTPUT I would like the date to show so I can sort by date. Do I need to use a CFSET on my form page, or a INPUT TYPE="hidden", or none of the above.

Thanks for your help!
    This topic has been closed for replies.
    Correct answer craigkaminsky
    If you want the date in a form field, add this to your form block:
    <input type="hidden" name="TodaysDate" value="<cfoutput>#DateFormat(Now(),'mmddyyyy')#</cfoutput>"/>

    The <cfoutput> tags are not needed if you are already using them around your form code.

    Depending on what you are doing, you might not need to use a hidden field and Walter's approach is better. If you do need a form field to hold this value, then use the approach above.

    Cheers,
    Craig

    2 replies

    craigkaminskyCorrect answer
    Inspiring
    May 7, 2007
    If you want the date in a form field, add this to your form block:
    <input type="hidden" name="TodaysDate" value="<cfoutput>#DateFormat(Now(),'mmddyyyy')#</cfoutput>"/>

    The <cfoutput> tags are not needed if you are already using them around your form code.

    Depending on what you are doing, you might not need to use a hidden field and Walter's approach is better. If you do need a form field to hold this value, then use the approach above.

    Cheers,
    Craig
    _Bryan_Author
    Known Participant
    May 7, 2007
    Walter's code worked except I'm getting some weird date returns:

    09/05/15786
    Inspiring
    May 7, 2007
    None of the above.

    Use cold fusion's now() function on your action page, not your form page.
    _Bryan_Author
    Known Participant
    May 7, 2007
    Thanks Dan,

    This is what I put on my action page:

    <cfquery datasource="POG">
    INSERT INTO Email(TodaysDate, EmailFrom, SubjectOf, Message, Name, Phone)
    VALUES('#TodaysDate(now(), "mmddyyyy")#', '#EmailFrom#', '#SubjectOf#', '#Message#', '#Name#', '#Phone#')
    </cfquery>
    <cflocation url="Contact_us.cfm">

    But this is the error that it returned: Variable TODAYSDATE is undefined.
    My apologies, but I'm still a bit new at this, and I'm still trying to figure out how this all functions.

    Thanks,
    Bryan
    Participant
    May 7, 2007
    Replace #TodaysDate(now(), "mmddyyyy")# by #Dateformat(now(), "mmddyyyy")# and it shoud work

    Walter