Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion - Form validation with null field

Posted on 2009-05-07
6
Medium Priority
?
604 Views
Last Modified: 2012-05-06
I am trying to have a message appear on the screen if there is a null value in a field in the table.  First it does not see the In_date field on the form because of the In_Date#rowNum# naming.  All I want is for the

 No videos checked out - choose another employee

message to appear when the in_date record field is null.  The first line of the if statement is pseudocode code

Any help is appreciated.

Thanks,
John
<cfif val(form.In_Date) eq null>
   No videos checked out - choose another employee
  <cfexit>
</cfif>
 
 
<cfform>
 
   <table width="1248" border="1">
   <cfoutput query="getChecked_Out_Videos">
     <cfset rowNum = getChecked_Out_Videos.currentRow>
     
     <tr>
          
    
       <td width="296">#Video_Name#</td>
       <td width="267">#Out_Date#</td>
       <td width="131"><select name="Watched#rowNum#" disabled="disabled">
						<option value='-1'> Watched</option>
						<option value='0' selected>Not Watched</option>
		    		   </select></td>
<td width="257"><input type="text"  disabled="disabled" name="In_Date#rowNum#" value="#getChecked_Out_Videos.In_Date#">
                  <input type="hidden" name="VideoID#rowNum#" value="#getChecked_Out_Videos.VideoID#">
       </td> 
       <td width="263"><a href="employeeEdit.cfm?employeeID=#EmployeeID#">Edit</a></td>
     </tr>
   </cfoutput>
  </table>       
<input type="hidden" name="totalRecords" value="#rowNum#">
  <input type="submit" name="submitButton"  value="Submit">
 
 
 
</cfform>

Open in new window

0
Comment
Question by:JohnMac328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24329886
ca you try say this

<cfif val(form.In_Date) eq ''>
   No videos checked out - choose another employee
  <cfexit>
</cfif>
or
<cfif len(trim(orm.In_Date)) gt 0>
   No videos checked out - choose another employee
  <cfexit>
</cfif>
0
 

Author Comment

by:JohnMac328
ID: 24329919
I tried that, I kept getting

Element IN_DATE is undefined in FORM.

The way that in_date is named with the name="In_Date#rowNum#" is what is tripping me up
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24332405
you code is very confusing... i can't figure out what exactly you want to check for: a form field value or a db column value? you are talking about checking the db record, but your code checks the form field value...
it is also not clear WHEN you want to check for the null value - after the form is submitted or before the form is rendered? confused...

anyway,

if you are checking for null value BEFORE the form is submitted, you can't refer to FORM scope, because it is still empty - FORM scope is populated with form fields values only after the form is submitted. so in this case you will need to check the values returned by your query, not values in your form fields, and you will need to do it inside your query output by using array notation: #queryname['columnname'][rownumber]#, i.e.
<cfform ...>
<cfoutput query="getChecked_Out_Videos">
<cfset rowNum = getChecked_Out_Videos.currentRow>
<cfif len(trim(getChecked_Out_Videos['in_date'][rownum])) is 0>
<p>No videos ...</p>
<cfelse>
... [you form fields here ]...
</cfif>
</cfoutput>
</cfform>

if you are checking for null values AFTER the form is submitted, then, to keep using your #rownum# identifiers, you will first have to run the same SELECT query that populated your form, and then again use array notation to test form field values:

<cfquery name="getChecked_Out_Videos" ...>
SELECT...
</cfquery>
<cfoutput query="getChecked_Out_Videos">
<cfset rownum = currentrow>
<cfif len(trim(form['In_date' & rownum])) is 0>
...
</cfif>
</cfoutput>

hope this helps.
if you clarify exactly where and when you want to check for null values, we can probably provide more relevant code sammples...

Azadi
0
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
LVL 39

Expert Comment

by:gdemaria
ID: 24332586
You're not testing for the right value.   The IN_DATE is part of your query "getChecked_Out_Videos"  therefore, it doesn't really make sense to test for it before the query starts to loop.

Wouldn't the check be simply to see if any records are returned by getChecked_Out_Videos ?

<cfif getChecked_Out_Videos.recordCount eq 0>
   No videos checked out...
   <cfexit>
</cfif>

Isn't the purpose of the form to allow the user to populate IN_DATE ?   So checking to see if IN_DATE is empty is kinda backwards?  You want in_date to be empty so the user can enter an IN_DATE, no?

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 total points
ID: 24332603
It seems that your query "getChecked_Out_Videos"  should be sure to only return videos that are out.   Which means there should be a wherer clause in that query that tests that IN_DATE is NULL


where IN_DATE is null  

- that would ensure the video is out and needs to be checked back in.   Then this code will make more sense, right?

<cfif getChecked_Out_Videos.recordCount eq 0>
   No videos checked out...
   <cfexit>
</cfif>
0
 

Author Closing Comment

by:JohnMac328
ID: 31579170
That's what I needed - I want to only show videos if they have one out since it is the checkin section.  

Thanks again.
0

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question