Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually there <em>is</em> a way to retrieve the data as an array. If your enctype is application/x-www-form-urlencoded (the default enctype) then you only need one line:</p> <pre><code>&lt;cfset myArray = getPageContext().getRequest().getParameterValues('my_form_or_url_field_name')&gt; </code></pre> <p>If your enctype is multipart/form-data (this is the type you use when uploading files) then things are a little more complicated. Here is a function I wrote that will return form &amp; url values with a given name as an array, for either enctype:</p> <pre><code>&lt;cffunction name="FormFieldAsArray" returntype="array" output="false" hint="Returns a Form/URL variable as an array."&gt; &lt;cfargument name="fieldName" required="true" type="string" hint="Name of the Form or URL field" /&gt; &lt;cfset var tmpPartsArray = Form.getPartsArray() /&gt; &lt;cfset var returnArray = arrayNew(1) /&gt; &lt;cfset var tmpPart = 0 /&gt; &lt;cfset var tmpValueArray = "" &gt; &lt;!--- if the getPartsArray method did not return NULL, then this is a multipart/form-data request, which must be handled as such. ---&gt; &lt;cfif IsDefined("tmpPartsArray")&gt; &lt;cfloop array="#tmpPartsArray#" index="tmpPart"&gt; &lt;cfif tmpPart.isParam() AND tmpPart.getName() EQ arguments.fieldName&gt; &lt;cfset arrayAppend(returnArray, tmpPart.getStringValue()) /&gt; &lt;/cfif&gt; &lt;/cfloop&gt; &lt;/cfif&gt; &lt;!--- Add the values that maybe on the URL with the same name, also if this *wasn't* a multipart/form-data request then the above code did not get any of the data, and the method below will return all of it. ---&gt; &lt;cfset tmpValueArray = getPageContext().getRequest().getParameterValues(arguments.fieldName) /&gt; &lt;!--- that may have returned null, so need to test for it. ---&gt; &lt;cfif IsDefined("tmpValueArray")&gt; &lt;cfloop array="#tmpValueArray#" index="tmpPart"&gt; &lt;cfset arrayAppend(returnArray, tmpPart) /&gt; &lt;/cfloop&gt; &lt;/cfif&gt; &lt;cfreturn returnArray /&gt; &lt;/cffunction&gt; </code></pre>
    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. 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.
    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