views:

638

answers:

1

below is the code i'm using to test this:

<cfif structkeyexists(form, "submitted")>
    <cfdump var="#getPageContext().getRequest().getParameterMap()#">
</cfif>

<cfoutput>
<form method="post" action="#cgi.script_name#?firstname=tony">
    <input type="text" size="50" name="page[contents][][content]">
    <input type="text" size="50" name="page[contents][][content]">
    <input type="hidden" name="submitted" value="1">
    <input type="submit">
</form>
</cfoutput>

what we're doing is using getPageContext().getRequest().getParameterMap() to retrieve a hash of the form and url scopes during a post request. now this work all fine and dandy until you set the enctype attribute of the form to "multipart/form-data‎" like so:

<cfif structkeyexists(form, "submitted")>
    <cfdump var="#getPageContext().getRequest().getParameterMap()#">
</cfif>

<cfoutput>
<form method="post" action="#cgi.script_name#?firstname=tony" enctype="multipart/form-data‎">
    <input type="text" size="50" name="page[contents][][content]">
    <input type="text" size="50" name="page[contents][][content]">
    <input type="hidden" name="submitted" value="1">
    <input type="submit">
</form>
</cfoutput>

what happens at this point is that none of the form field value are returned in the hash returned from getPageContext().getRequest().getParameterMap().

does anyone know where or how we can get this data or a workaround?

the whole reason we're using getPageContext().getRequest().getParameterMap() is because it returns an array as the value of the variable instead of a comma delimited list like using the form scope does.

UPDATE: this is on 8.0.1 with cumlative hotfix 4 applied.

UPDATE: The reason you can't use listToArray is because say you have two fields named firstname and the user enter in values for both fields (1 and 2). what CF will do is return a key in the form struct called firstname with a comma delimeted list for the two values (1,2). this is great, but say the user enters in values for the field that contain commas like 1,2,3,4 for the first field and 5,6,7,8 for the second field. the value in the form struct for firstname will be 1,2,3,4,5,6,7,8. this isn't correct. now since getParameterMap() returns an array for the value, i would have two elements like so: ["1,2,3,4","5,6,7,8"].

UPDATE: Tried seeing what getHttpRequestData().content would return per Leigh's suggest. It appears to be a blank binary.

UPDATE: Thanks you Leigh for figuring this out and without using getPageContext entirely. the trick was using getPartsArray() method on the form scope. I didn't even know this existed!

Keep the ideas coming please!

+1  A: 

(Okay.. take two) This seems to work with CF9. I am not able to test it with CF8 at the moment. Can you give it a whirl?

<cfif structkeyexists(form, "submitted")>
   <!--- if this is a multipart request ...--->
   <cfset variables.parts = form.getPartsArray()>
   <cfif structKeyExists(variables, "parts")>
      <cfoutput>   
      <cfloop array="#variables.parts#" index="p">
         <cfif p.isParam()>
            isParam() = #p.isParam()# <br />
            getName() = #p.getName()# <br />
            stringValue() = #p.getStringValue()# <hr />
         </cfif>
      </cfloop>
      </cfoutput>
   </cfif>
</cfif>
Leigh
I could hug you!!! Confirmed that this work in CF8!
rip747
how in the world did you figure this out? please explain
rip747
It was an interesting problem, so I wrote up a quick blog entry on it. Feel free to skip to the end ;) http://cfsearching.blogspot.com/2010/02/form-field-values-multipart-forms-and.html
Leigh
BTW: I forgot to say, glad it is solved .. and cool question :)
Leigh