Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

Coldfusion - Form date picker

I am trying to get a coldfusion date popup script to work.  I have changed the names to fit my form and application but I keep getting a "The web site you are accessing has experienced an unexpected error. Please contact the website administrator." error in the popup window.  I have submitted the orginal and my converted files.  The original files will work in your folder with no modifications. Any help is appreciated.

Thanks,
John
popcalendar.txt
poppedup.txt
poppedupVideoOne.txt
VideoCheckout.txt
Avatar of _agx_
_agx_
Flag of United States of America image

What version of CF are you using again?  If you are using CF8, it has a built in date picker:



<cfif structKeyExists(form, "selectedDate")>
	<cfoutput>
	You selected:  #form.selectedDate#
	</cfoutput>
</cfif>
 
<cfform action="#CGI.SCRIPT_NAME#" method="post" format="html">
	<cfinput type="datefield" name="selectedDate">
	<input type="submit" value="Test Calendar">
</cfform>

Open in new window

Avatar of JohnMac328

ASKER

I don't get any errors but the movie is not checking out to the employee.  It did before when I keyed in the date.  I must be missing something


<cfif not IsDefined('SESSION.EmployeeID')>
  <cflocation url="login.cfm">
</cfif>
 
<cfif structKeyExists(FORM, "submit")>
 
<CFSET new_date = #CREATEODBCDATETIME(Out_Date)#>
 
  <cfparam name="form.watched" default="no">
 
  <cfquery name="enterdetails" datasource="#datasource#">
    INSERT INTO Detail (EmployeeID, VideoID, Out_Date)
    VALUES
    (
        <cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer"> ,
        <cfqueryparam value="#form.VideoID#" cfsqltype="cf_sql_integer"> ,
         <cfqueryparam value="#new_date#" cfsqltype="CF_SQL_TIMESTAMP">
 
       
   
    )
   
    </cfquery>
 
</cfif>
 
 
 
 
<cfquery name="getAllEmployees" datasource="#datasource#">
   SELECT  EmployeeID, First_Name, Last_Name, Email
   FROM    Employees
   ORDER BY Last_Name, First_Name
 </cfquery>
 
<cfquery name="getAllFilms" datasource="#datasource#">
  SELECT VideoList.VideoID, VideoList.Video_Name, VideoList.Length, VideoList.Production_Company, Category.Category_Name, VideoList.Tests, VideoList.Availability, Detail.Out_Date
FROM Category INNER JOIN (VideoList INNER JOIN Detail ON VideoList.VideoID = Detail.VideoID) ON Category.Category_ID = VideoList.CategoryID
 </cfquery>
 
 
 
<cfform action="videoCheckout.cfm" method="post" format="html">
        
        <table width="700">
		<tr>
        <td>
      <select name="employeeID">
          <cfoutput query="getAllEmployees">
             <option value="#employeeID#">#Email#</option>
          </cfoutput>
      </select>
    </td>
      <td>
      <select name="VideoID">
          <cfoutput query="getAllFilms">
             <option value="#VideoID#">#Video_Name#</option>
          </cfoutput>
      </select>
      
       
  <td>
      
      <cfinput type="datefield" name="Out_Date">
   
   </td>
        
        
        
        
        
        
        <input type="submit" value="Submit">
</cfform>

Open in new window

Make sure the submit button has the name "submit". Otherwise your CFIF code won't fire.

    <input type="submit" name="submit" value="Submit">
I caught that and changed it, still runs but does not enter the movie data.  I have the old version and it does when I type in the date.

 
<style>
input{ font-size: 10pt; color: #000000;	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;}
</style>
 
<cfif not IsDefined('SESSION.EmployeeID')>
  <cflocation url="login.cfm">
</cfif>
 
<cfif structKeyExists(FORM, "submitButton")>
 
<CFSET new_date = #CREATEODBCDATETIME(Out_Date)#>
 
  <cfparam name="form.watched" default="no">
 
  <cfquery name="enterdetails" datasource="#datasource#">
    INSERT INTO Detail (EmployeeID, VideoID, Out_Date)
    VALUES
    (
        <cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer"> ,
        <cfqueryparam value="#form.VideoID#" cfsqltype="cf_sql_integer"> ,
         <cfqueryparam value="#new_date#" cfsqltype="CF_SQL_TIMESTAMP">
 
       
   
    )
   
    </cfquery>
 
</cfif>
 
<!---  <cfquery name="Check_UserRole" datasource="library">
Select role
FROM Users
Where User_id = '#session.User_id#'
</cfquery>--->
 
 
<cfquery name="getAllEmployees" datasource="#datasource#">
   SELECT  EmployeeID, First_Name, Last_Name, Email
   FROM    Employees
   ORDER BY Last_Name, First_Name
 </cfquery>
 
<cfquery name="getAllFilms" datasource="#datasource#">
  SELECT VideoList.VideoID, VideoList.Video_Name, VideoList.Length, VideoList.Production_Company, Category.Category_Name, VideoList.Tests, VideoList.Availability, Detail.Out_Date
FROM Category INNER JOIN (VideoList INNER JOIN Detail ON VideoList.VideoID = Detail.VideoID) ON Category.Category_ID = VideoList.CategoryID
 </cfquery>
 
 
 
<form method="post" style="margin:0px"  action="videoCheckoutbk.cfm">
  <table width="700">
		<tr>
        <td>
      <select name="employeeID">
          <cfoutput query="getAllEmployees">
             <option value="#employeeID#">#Email#</option>
          </cfoutput>
      </select>
    </td>
      <td>
      <select name="VideoID">
          <cfoutput query="getAllFilms">
             <option value="#VideoID#">#Video_Name#</option>
          </cfoutput>
      </select>
      
      <td><input type="text" name="Out_Date" size="30"></td>
			
			 
			
      
 
 
  
 
    
 <!---<cfif check_user.Role('Admin')>
 code to show for Admin users only
</cfif> 
 <td><cfif session.role eq 1>
 
     <input type="radio" name="watched" value="yes"> Yes
      <input type="radio" name="watched" value="no" checked> No
      </cfif>
       </td>
 
  <td>
 
  <input type="radio" name="checked_out" value="yes"> Yes
      <input type="radio" name="checked_out" value="no" checked> No
 </td>--->
     
      <input type="submit" name="submitButton">
</tr>
	</table>
</form>
 
 
 
 
 
 
 

Open in new window

Is it throwing an error or just not inserting anything?  As long as the cfif is firing, I would expect either an error or for the record to be inserted.

Try add some debugging code to the query.  What results do you get?

<cfif structKeyExists(FORM, "submit")>
    <CFSET new_date = #CREATEODBCDATETIME(Out_Date)#>
    <cfparam name="form.watched" default="no">
     <cfdump var="#FORM#" label="Form Values">

    <cfquery name="enterdetails" datasource="#datasource#" result="myResults">
         ... same sql here ...
    </cfquery>
     <cfdump var="#myResults#" label="Query Results">
</cfif>
Ok, first I get no error and nothing gets inserted with the new date function.  Second I get nothing with the new cfdump, I'm getting confused
<CFSET new_date = #CREATEODBCDATETIME(Out_Date)#>
 
   <cfdump var="#FORM#" label="Form Values">
 
  <cfquery name="enterdetails" datasource="#datasource#" result="myResults">
    INSERT INTO Detail (EmployeeID, VideoID, Out_Date)
    VALUES
    (
        <cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer"> ,
        <cfqueryparam value="#form.VideoID#" cfsqltype="cf_sql_integer"> ,
         <cfqueryparam value="#new_date#" cfsqltype="CF_SQL_TIMESTAMP">
 
       
   
    )
   
    </cfquery>
<cfdump var="#myResults#" label="Query Results">
</cfif>

Open in new window

Oops. I didn't notice your button was named "submitButton".  I corrected that.  Also, it should at least display a message if the submit button was not found (or the first time the page is loaded).  Try it again now.  

>  I get nothing with the new cfdump,

If you are not seeing anything at all .. it is most likely that the CFIF is not firing.  So I added an cfelse clause. So at least you will see _some_ message if it is not firing.


<cfif structKeyExists(FORM, "submitButton")>
    <CFSET new_date = #CREATEODBCDATETIME(Out_Date)#>
    <cfparam name="form.watched" default="no">
     <cfdump var="#FORM#" label="Form Values">
 
<cfquery name="enterdetails" datasource="#datasource#" result="myResults">
    INSERT INTO Detail (EmployeeID, VideoID, Out_Date)
    VALUES
    (
        <cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer"> ,
        <cfqueryparam value="#form.VideoID#" cfsqltype="cf_sql_integer"> ,
         <cfqueryparam value="#new_date#" cfsqltype="CF_SQL_TIMESTAMP">
 
       
   
    )
     <cfdump var="#myResults#" label="Query Results">
<cfelse>
  form.submitButton does not exist
</cfif>

Open in new window

Ok, I get the  form.submitButton does not exist  message on the screen.  Why does it not see the submit button?  

Here is the form


<cfform action="videoCheckout.cfm" method="post" format="html">
        
        <table width="700">
		<tr>
        <td>
      <select name="employeeID">
          <cfoutput query="getAllEmployees">
             <option value="#employeeID#">#Email#</option>
          </cfoutput>
      </select>
    </td>
      <td>
      <select name="VideoID">
          <cfoutput query="getAllFilms">
             <option value="#VideoID#">#Video_Name#</option>
          </cfoutput>
      </select>
      
       
  <td>
      
      <cfinput type="datefield" name="Out_Date">
   
   </td>
        
        
        
        
        
        
        <input type="submitButton" value="Submit">
</cfform>

Open in new window

> <input type="submitButton" value="Submit">

You took out the name again ;-)   That happens when testing new code.  

Just make sure the button name is the same as what you are using in the CFIF statement:

     <!--- both values must be the same ---->
      <cfif structKeyExists(FORM, "submitButton")>  
       .....
       <input type="submitButton" name="submitButton"  value="Submit">
I still get the  form.submitButton does not exist  message on the screen.  The only difference is that I am using the cold fusion form, does it have a special name for submit buttons?

 
<style>
input{ font-size: 10pt; color: #000000;	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;}
</style>
 
<cfif not IsDefined('SESSION.EmployeeID')>
  <cflocation url="login.cfm">
</cfif>
 
<cfif structKeyExists(FORM, "submitButton")>
 
<CFSET new_date = #CREATEODBCDATETIME(Out_Date)#>
 
   <cfdump var="#FORM#" label="Form Values">
 
  <cfquery name="enterdetails" datasource="#datasource#" result="myResults">
    INSERT INTO Detail (EmployeeID, VideoID, Out_Date)
    VALUES
    (
        <cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer"> ,
        <cfqueryparam value="#form.VideoID#" cfsqltype="cf_sql_integer"> ,
         <cfqueryparam value="#new_date#" cfsqltype="CF_SQL_TIMESTAMP">
 
       
   
    )
   
    </cfquery>
<cfdump var="#myResults#" label="Query Results">
 
<cfelse>
  form.submitButton does not exist
</cfif>
 
 
 
 
<cfquery name="getAllEmployees" datasource="#datasource#">
   SELECT  EmployeeID, First_Name, Last_Name, Email
   FROM    Employees
   ORDER BY Last_Name, First_Name
 </cfquery>
 
<cfquery name="getAllFilms" datasource="#datasource#">
  SELECT VideoList.VideoID, VideoList.Video_Name, VideoList.Length, VideoList.Production_Company, Category.Category_Name, VideoList.Tests, VideoList.Availability, Detail.Out_Date
FROM Category INNER JOIN (VideoList INNER JOIN Detail ON VideoList.VideoID = Detail.VideoID) ON Category.Category_ID = VideoList.CategoryID
 </cfquery>
 
 
 
<cfform action="videoCheckout.cfm" method="post" format="html">
        
        <table width="700">
		<tr>
        <td>
      <select name="employeeID">
          <cfoutput query="getAllEmployees">
             <option value="#employeeID#">#Email#</option>
          </cfoutput>
      </select>
    </td>
      <td>
      <select name="VideoID">
          <cfoutput query="getAllFilms">
             <option value="#VideoID#">#Video_Name#</option>
          </cfoutput>
      </select>
      
       
  <td>
      
      <cfinput type="datefield" name="Out_Date">
   
   </td>
        
        
        
        
        
        
         <input type="submitButton" name="submitButton"  value="Submit">
</cfform>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That time it took, thanks again agx.  I'll be back :)
You are welcome.  See you around :)