database - In ColdFusion, how can I extract and store the contents of the submitted form? -


I am writing an application in ColdFusion, and even if it is more stable, errors are not present every time because it is already The old app has changed, sometimes this user who gets errors instead of me.

I have created a good page when people receive an error which sends me information, such as error, referrer, error, on which the page, line number etc.

The only thing that can not seem to work for me, if any, is submitting the form data. I do not know what was wrong with this page, so I just got "# Can not produce 'form.field #'. For example:

  form. ABC = 1 form.def = 2  

How can I get variable names and values ​​from 'form' without knowing them already?

Is there anywhere on the right track?

In addition to this, I am looking for a good way to store that data in the database, because in the situation where the other information about the error is stored, and I really do not have to keep it for me An email is in.

There is a fieldname variable in the form of the form, Fields were submitted from

You can also StructKeyList (form) to get a list of existing variables in the scope. This one will also include FieldName and any other variables that have been added later in the form scope.

Do any of these & lt; Cfloop index = "CurField" list = "#StructKeyList (form) #" & gt; - But there are easy ways ...


If you are on CF8, then you must call this field to and deserializeJson () functions, which can then be stored in the appropriate database field.

If you 're again on CF 6. 7 then you can download a CFC which is copied to these tasks.


Finally, if you are on the first version of CF or have a strange bottleneck to use JSON for storage, Can you roll yourself with a simple loop - a collection loop lets you loop directly through a structure or scope - note that some annoying person has chosen 'item' instead of 'item' for them. The 'Index' as the attribute

Since we know that form variables are all simple objects (i.e. strings) I have a basic key = value [newline] key = value [newline] ... format It is easy to reverse whatever is done.

Encoding:

  & lt; Cfset output = '' / / gt; & Lt; Cfloop item = "CurField" collection = "#form #" & gt; & Lt; Cfset output = output & amp; Curiefild & amp; '=' & Amp; Form [curryfield] & amp; Chr (10) /> & Lt; / Cfloop & gt; & Lt; Cfoutput & gt; # Output # & lt; / Cfoutput & gt;  

Decoding:

  & lt; Cfset FormData = StructNew () /> & Lt; Cfloop index = "curline" list = "# output #" delimited = "# chr (10) #" & gt; & Lt; Cfset form data [list first (curline, '=') = listrest (curline, '=') /> & Lt; / Cfloop & gt; & Lt; Cfdump var = "#formdata #" /> One last important note: All the variables provided by the user (form, url, cookie scope) will need to ensure that you want to handle them correctly. To prevent safety holes - especially   make sure that you    all    are using cfqueryparam    - Do not want to get too far, but if you need any help with CFQPPP then do not hesitate to ask another question. 


Hope this is helpful :)


Comments