Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Form scope has a <code>FieldNames</code> variable which will tell you what fields were submitted.</p> <p>You can also do <code>StructKeyList(Form)</code> to get a list of the current variables in the scope. This one will also include FieldNames and any other variables that have since been added to the Form scope.</p> <p>Either of these could be used inside a <code>&lt;cfloop index="CurField" list="#StructKeyList(Form)#"&gt;</code> - but there are easier ways...</p> <p><br/></p> <p>If you are on CF8 you can convert the scope to a string nice and easily with <code>serializeJson()</code> and <code>deserializeJson()</code> functions, which could then be stored in a suitable database field.</p> <p>If you're on CF6..7 then you can download a CFC called <a href="http://cfjson.riaforge.org" rel="nofollow noreferrer">cfjson</a> from <a href="http://www.riaforge.org" rel="nofollow noreferrer">riaforge</a> which mimics these functions.</p> <p><br/></p> <p>Finally, if you're on earlier versions of CF, or have an odd aversion to using JSON for storage, you can roll your own with an even simpler loop to the one hinted above - a collection loop lets you loop directly through a Structure or Scope - note that some annoying person picked 'item' rather than 'index' as the attribute for these.</p> <p>Since we know Form variables are all simple objects (i.e. strings) I've elected for a basic <code>key=value[newline]key=value[newline]...</code> format, which is easy to reverse also.</p> <p>Encoding:</p> <pre><code>&lt;cfset Output = '' /&gt; &lt;cfloop item="CurField" collection="#Form#"&gt; &lt;cfset Output = Output &amp; CurField &amp; '=' &amp; Form[CurField] &amp; Chr(10) /&gt; &lt;/cfloop&gt; &lt;cfoutput&gt;#Output#&lt;/cfoutput&gt; </code></pre> <p>Decoding:</p> <pre><code>&lt;cfset FormData = StructNew()/&gt; &lt;cfloop index="CurLine" list="#Output#" delimiters="#Chr(10)#"&gt; &lt;cfset FormData[ListFirst(CurLine,'=')] = ListRest(CurLine,'=') /&gt; &lt;/cfloop&gt; &lt;cfdump var="#FormData#"/&gt; </code></pre> <p><br/></p> <p>One last important note: As with all user-supplied variables (Form,Url,Cookie scopes) you must make sure you handle them correctly to prevent security holes - specifically <strong><em>make sure you are using cfqueryparam for</em></strong> <strong>all</strong> <strong><em>your database queries</em></strong> - don't want to sidetrack too far, but feel free to ask another question if you need any help with cfqueryparam.</p> <p><br/></p> <p>Hope this helps. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload