Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date Validation

New Here ,
Jun 24, 2009 Jun 24, 2009

I am trying to validate the date in this application.  If the user does not enter a date, it throws an exception but does not return an error message, and the record insert into the DB2 database does not occur.  The database date field defaults to today's date.  Any suggestions on why this is not working, or how to accomplish this?  Code examples are greatly appreciated.

Thank you,

Jeanne

____________________________________________________

<html>
<head>
<title>CAF Survey Form</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
-->
</style>
</head>
<body bgcolor="#CCFFFF"><span class="style1">
<h2 align="center">Enter a CAF Survey Form</h2><br>

<cfform action="surveyAction.cfm" method="post">

<script language="JavaScript">
<!--
document.location.href = "http://localhost:8500/cafsurvey/surveyForm.cfm;
//-->
</script>

<table>
<tr>
<td width="33">
</td>
<td>

Date:
<cfinput type="datefield" name="SURVEY_DATE" size="10" maxlength="10" validateat="onBlur" validate="required,date" message="Please enter a date!">            <br><br><br>

Branch:
<cfinput type="text" name="BRANCH" size="4" maxlength="4"><br><br><br>

1. Did you get what you needed today?                                                 
<cfinput type="radio" name="NEED_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="NEED_FLG" id="radio" value="N">No
<cfinput type="radio" name="NEED_FLG" id="radio" value="X" checked>Did Not Answer<br><br>

          If not, please explain:  
<cftextarea name="NEED_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

2. Did you receive information about other community resources?   
<cfinput type="radio" name="RESOURCE_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="RESOURCE_FLG" id="radio" value="N">No
<cfinput type="radio" name="RESOURCE_FLG" id="radio" value="X" checked>Did Not Answer<br><br><br>

3. How long did you wait in the office to be seen today?              Minutes     Hours
   Did Not Answer<br>                                                                                                            
<cfinput type="text" name="WAIT_MIN" size="2" maxlength="2" required="no" value="0">   
<cfinput type="text" name="WAIT_HRS" size="2" maxlength="2" required="no" value="0">              
<cfinput type="checkbox" name="WAIT_FLG" value="X"><br><br><br>

4. How long did it take to get today's appointment??          Hours        Days      Weeks
   Did Not Answer<br>                                                                                                  
<cfinput type="text" name="APPT_HRS" size="2" maxlength="2" required="no" value="0">   
<cfinput type="text" name="APPT_DAYS" size="2" maxlength="2" required="no" value="0">   
<cfinput type="text" name="APPT_WEEKS" size="2" maxlength="2" required="no" value="0">              
<cfinput type="checkbox" name="APPT_FLG" value="X"><br><br><br>

5. Did you have enough time during your appointment to <br>
   tell your case worker what you wanted or needed?                           
<cfinput type="radio" name="TIME_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="TIME_FLG" id="radio" value="N">No
<cfinput type="radio" name="TIME_FLG" id="radio" value="X" checked>Did Not Answer <br><br>

          If not, please explain:  
<cftextarea name="TIME_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

6. Did you get all of your questions answered?                                     
<cfinput type="radio" name="ANSWERS_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="ANSWERS_FLG" id="radio" value="N">No
<cfinput type="radio" name="ANSWERS_FLG" id="radio" value="X" checked>Did Not Answer<br><br>

          If not, please explain:  
<cftextarea name="ANSWERS_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

7. How was the service today?                                                               
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="E">Excellent
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="G">Good
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="F">Fair
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="P">Poor
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="X" checked>Did Not Answer<br><br>

                          Comments:  
<cftextarea name="SERVICE_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

8. Would you like to share any other information about your visit today?<br><br>
                                                
<cftextarea name="OTHER_INFO" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

9. Are there any unresolved issues that you would <br>
   like to have addressed?                                                                       
<cfinput type="radio" name="UNRESOLVED_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="UNRESOLVED_FLG" id="radio" value="N">No
<cfinput type="radio" name="UNRESOLVED_FLG" id="radio" value="X" checked>Did Not Answer<br><br><br>

If you would like someone to contact you, please include your name and phone number:<br><br>          
Name: <cfinput type="text" name="CONTACT_NAME" size="40" maxlength="40" required="no">     
Phone: <cfinput type="text" name="CONTACT_PHONE" size="10" maxlength="10" required="no" validate="telephone" message="Please enter a valid phone number!">

<!--- <cftextarea name="NEED_COMMENT" height="3" width="800" size="200" maxlength="200"></cftextarea> --->

<!--- <textarea name="Needcomments" cols="50" rows="3" id="Needcomments" tabindex="35" onFocus="this.rows=4" onBlur="this.rows=1" onSelect="this.rows=4" onKeyDown="limitText('comments','countdown_comments',200);" onKeyUp="limitText('comments','countdown_comments',200);"> </textarea> --->

<br><br><br>
<input type="Submit" value="Submit">          <input type="Reset"
value="Clear Form">


</td>
</table>

</cfform>

</body></span>
</html>

_____________________________________________________________________

<html>
<head> <title>Insert Survey Form</title> </head>
<body>

<!--- Insert the new record --->

<cfset needCom = left(NEED_COMMENT,200)>
<cfset timeCom = left(TIME_COMMENT,200)>
<cfset answersCom = left(ANSWERS_COMMENT,200)>
<cfset serviceCom = left(SERVICE_COMMENT,200)>
<cfset otherInfo = left(OTHER_INFO,200)>

<cfif isdefined ("form.WAIT_FLG")>
<cfset form.WAIT_FLG = "X">
<cfelse>
<cfset form.WAIT_FLG = "N">
</cfif>

<cfif isdefined ("form.APPT_FLG")>
<cfset form.APPT_FLG = "X">
<cfelse>
<cfset form.APPT_FLG = "N">
</cfif>

<cfquery datasource="AXMISC_SURVEY">
   INSERT INTO SURVEY.CAF_SURVEY
   (SURVEY_DATE, BRANCH, NEED_FLG, NEED_COMMENT, RESOURCE_FLG, WAIT_MIN, WAIT_HRS, WAIT_FLG, APPT_HRS, APPT_DAYS, APPT_WEEKS, APPT_FLG, TIME_FLG, TIME_COMMENT, ANSWERS_FLG, ANSWERS_COMMENT, SERVICE_FLG, SERVICE_COMMENT, OTHER_INFO, UNRESOLVED_FLG, CONTACT_NAME, CONTACT_PHONE)
   VALUES
   ( <cfqueryparam cfsqltype="cf_sql_date" value="#form.SURVEY_DATE#">,
     <cfqueryparam cfsqltype="cf_sql_char" value="#form.BRANCH#">,
     <cfqueryparam cfsqltype="cf_sql_char" value="#form.NEED_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#needCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.RESOURCE_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_MIN#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_HRS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_HRS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_DAYS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_WEEKS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.TIME_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#timeCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.ANSWERS_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#answersCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.SERVICE_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#serviceCom#>,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#otherInfo#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.UNRESOLVED_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.CONTACT_NAME#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.CONTACT_PHONE#">
   )
</cfquery>

<cflocation url="http://localhost:8500/cafsurvey/surveyForm.cfm" addtoken="No">


<script language="JavaScript">
<!--
document.location.href = "http://localhost:8500/cafsurvey/surveyForm.cfm;
//-->
</script>

<!--- <cfoutput>You have added #CONTACT_NAME# to the
Client Survey database.
</cfoutput>   --->
</body>
</html>

1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 28, 2009 Jun 28, 2009

Hi,

try this

<cfquery datasource="AXMISC_SURVEY">
   INSERT INTO SURVEY.CAF_SURVEY
   (

<cfif isdefined("form.SURVEY_DATE") AND len(trim(form.SURVEY_DATE))>

SURVEY_DATE,

</cfif>

BRANCH,

NEED_FLG, NEED_COMMENT, RESOURCE_FLG, WAIT_MIN, WAIT_HRS, WAIT_FLG, APPT_HRS, APPT_DAYS, APPT_WEEKS, APPT_FLG, TIME_FLG, TIME_COMMENT, ANSWERS_FLG, ANSWERS_COMMENT, SERVICE_FLG, SERVICE_COMMENT, OTHER_INFO, UNRESOLVED_FLG, CONTACT_NAME, CONTACT_PHONE)
   VALUES
   (

<cfif isdefined("form.SURVEY_DATE") AND len(trim(form.SURVEY_DATE))>

<cfqueryparam cfsqltype="cf_sql_date" value="#form.SURVEY_DATE#">,

</cfif>


     <cfqueryparam cfsqltype="cf_sql_char" value="#form.BRANCH#">,
     <cfqueryparam cfsqltype="cf_sql_char" value="#form.NEED_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#needCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.RESOURCE_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_MIN#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_HRS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_HRS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_DAYS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_WEEKS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.TIME_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#timeCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.ANSWERS_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#answersCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.SERVICE_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#serviceCom#>,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#otherInfo#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.UNRESOLVED_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.CONTACT_NAME#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.CONTACT_PHONE#">
   )
</cfquery>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2009 Jul 06, 2009

Hi,

I tried the code above to validate the date.  I am still getting the same response:  it does not insert the record into the DB2 database, and it does not return and error message for the user.  I prefer to have the validation occur onBlur (in addition to server side validation), but have not been able to get that to work.  Some of the other elements on validated onSubmit.

Thank you for your help,

Jeanne

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2009 Jul 10, 2009
LATEST

HI

It seems like validateat="onblur" wont work if the type is date field

you can try the following

<cfinput type="datefield" name="SURVEY_DATE" validateat="onsubmit" size="10" maxlength="10" required="yes" validate="date" message="Please enter a date!">

(note that  required="yes" is the correct syntax not validate="required")

The above code will work onsubmit

But as you said if you prefer to provide validation onblur you can use js function called on blur

code snippet is as follows

<script language="javascript" type="text/javascript">
function checkDate()
{


         if(document.getElementById("SURVEY_DATE").value == "")
          {
                     alert("Please enter a date!");
                     document.getElementById("SURVEY_DATE").focus();
          }
}
</script>

<cfinput type="datefield" name="SURVEY_DATE" id="SURVEY_DATE" validateat="onsubmit" size="10" maxlength="10" required="yes" validate="date" message="Please enter a date!" onBlur="checkDate()">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources