Solved

Coldfusion Error

Posted on 2014-02-23
12
319 Views
Last Modified: 2014-02-24
Hi,
 
 I am getting "Element ITEMNO is undefined in FORM. " error on my coldfusion page.

 First, I use CFGRID to display records in flash. When the user clicks any record/row in the grid, I display the contetns of each field and let the user change it. When the user clicks [Save Change] button, I try to update the change(s), but that is where the error occurs.
 Please see WORD doc for details.

Thanks.
CFCode.doc
0
Comment
Question by:sglee
  • 7
  • 5
12 Comments
 
LVL 4

Accepted Solution

by:
Rodrigo Munera earned 500 total points
ID: 39881538
Is all the code in your ms word document on one file? or is it spread in different .cfm files? what's the data flow? the screenshots and the code don't seem to correspond.

What's the workflow?

The most glaring error I can see is that your cfparam names are not in the form scope.

a simple fix of your code would be to turn your <cfparam name="itemNo" default=""> into <cfparam name="form.itemNo" default="">

You'll have to do that with all your cfparam tags to get the page to execute without issues.
0
 
LVL 4

Expert Comment

by:Rodrigo Munera
ID: 39881554
Also you have two separate forms,

The first form has all your form data (cfform posting to menu.cfm) and your second form (form posting to AdminItemUpdate.cfm) has your submit button and your ID and cfgridID in a hidden field. So when you hit submit, you're only submitting the second form.

You should put all your input elements into one form with all the elements your want to submit. Otherwise you're not going to pass all the data to the action page.
0
 

Author Comment

by:sglee
ID: 39881562
Sorry about not being clear. Here is the order.
AdminMenu.cfm  : Main menu.
AdminBrowseFolder.cfm :  CFGRID to display records in the inventory table.
AdminItemDetails.cfm?cfgridkey=14   : User selected 14th row to edit contents.
AdminItemUpdate.cfm : update the record with change(s).

Since I added "form.column_name" like <cfparam name="form.itemNo" default="">, those errors were gone. Also replaced     WHERE   ID = <cfqueryparam value="#cfgridkey#" cfsqltype="cf_sql_integer"> with WHERE   ID = cfgridkey.

Now I am getting this error:
Error Executing Database Query.  
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.  

So I am going to chekc the syntax of my query:
      <CFQUERY NAME="UpdateRecord" DATASOURCE="WhatsThePoint">
              UPDATE       Inventory
            SET            ItemNo = '#Form.ItemNo#',
                        Title = '#Form.Title#',
                        CategoryID = #Form.CategoryID#,
                        DesignerID = #Form.DesignerID#,
                        Status = #Form.Status#,
                        Description = '#Form.Description#',
                        ListPrice = #Form.ListPrice#,
                        SalePrice = #Form.SalePrice#,
                        Size = '#Form.Size#',
                        MeshCount = #Form.MeshCount#,
                        Qty = #Form.Qty#,
                        Size = '#Form.Size#',
                        PictureFileName = '#Form.PictureFileName#',
                        PicturePath = '#Form.PicturePath#'
    WHERE   ID = cfgridkey
      </CFQUERY>
0
 

Author Comment

by:sglee
ID: 39881571
Well, the above CFquery did not work even with one field "ItemNo". So I took out the entire CFQuery and put in the following for troubleshooting:
 <CFOUTPUT>
ITEM NO: #Form.ItemNo#
</CFOUTPUT>

and no data was displayed, not even the heading "ITEM NO".

Is there a way that I can simply use
<cfupdate datasource="DSN_Name" tablename="Inventory">  ?
0
 
LVL 4

Expert Comment

by:Rodrigo Munera
ID: 39881574
See my second message, fixing the params will get rid of your CF errors but it will not make sure you're getting the data from your form page to your query update statement.

The way HTML forms work is that whatever you put between <form> and </form> will get sent in to the action page. (<cfform> renders as <form> in the actual page), so if you have <cfform> <data1 /> </cfform> and then another form <form> <data2 /> <input type="submit"></form>, once you hit that submit button, you will only get the <data2 /> sent to your action page. While you won't have any coldfusion (syntax) errors because you initialized the form data with cfparams, it doesn't guarantee that the <data1 /> you want to submit will make it to your update statement.

On another note, having your update statement using open SQL items like:

ItemNo = '#Form.ItemNo#'

Opens your code to SQL injection attack, you should always sanitize your database inputs using <cfqueryparam> tags so your data is protected (also data validation code would be helpful to make sure you're not sending bad data to your database).
0
 

Author Comment

by:sglee
ID: 39881579
Here is the code as it is and it does not update the data at all. I don't think it is passing any data either.
CFCode2.doc
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:Rodrigo Munera
ID: 39881582
A short note about your question about using cfupdate:

Yes, you can but be careful on how you use it and where you implement it (can be abused by hackers if you don't set it up properly.

There's a good article on the subject here: http://cfmlblog.adamcameron.me/2012/07/are-cfinsert-and-cfupdate-as-bad-as.html
0
 
LVL 4

Expert Comment

by:Rodrigo Munera
ID: 39881594
Your form code posts form data fine to the action page.

To see what data is being posted from the form, you can dump the form scope at the beginning of the action page by using <cfdump var="#form#"> (before the cfparams)

Also, you probably don't want to just blindly cfparam all your variables, otherwise you may get a database table row with blank values if you're not careful. Validate your input from your forms before you allow your action page to update your database.
0
 

Author Comment

by:sglee
ID: 39881595
CF DumpIt passes no data.
0
 
LVL 4

Expert Comment

by:Rodrigo Munera
ID: 39881603
Your form fields are being passed, it's just that you have set the text to white so you can't see the values, if data was not being passed, you wouldn't get the form fields defined as they are on your dump.

Also if no data was being passed for a field, the dump would say "[empty string]", it wouldn't just be blank

If you use ctrl+a, you'll see the text being passed.

Screenshot of Form posted to itself and form scope cfdumped
0
 

Author Comment

by:sglee
ID: 39881631
With Contrl-A, I was able to see data passed. Why CFGridKey failed to make it?
0
 
LVL 4

Expert Comment

by:Rodrigo Munera
ID: 39881651
Look at the source code on your browser of AdminItemDetails.cfm

Look at the hidden input. It's probably blank.

Where is your cfgridkey coming from? If your cfgridkey is in your URL query, you should scope it correctly in your form like so:

<input type="hidden" name="cfgridkey" value="#URL.cfgridkey#" />
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now