Re: post leaves out form variables with empty values
"John C. Mallery" <[email protected]> Fri, 25 Jun 2004 10:56:59 -0400
| Newsgroups | gmane.lisp.cl-http |
|---|---|
| Message-ID | <p0602040bbd01ecf104d9@[128.30.5.129]> |
At 2:22 PM +0100 6/25/04, Martin Simmons wrote: > >>>>> On Thu, 24 Jun 2004 23:47:24 -0400, Mark Klein <[email protected]> said: > > Mark> I traced a problem in my server to the following fact: As the example > Mark> below will show, if you create a fillout-form which gets some > Mark> strings, and the user leaves some fields blank when filling it out, > Mark> the query-alist passed to the response function *leaves out* the > Mark> variables for which no values were entered, as opposed for example to > Mark> including the variables with null strings as their value. > > Mark> (defmethod show-form ((url url:http-form) stream) > Mark> (http:with-successful-response (stream :html) > Mark> (html:with-fillout-form (:post url :stream stream) > Mark> (html:accept-input 'html:string "v1" :stream stream) > Mark> (html:accept-input 'html:string "v2" :stream stream) > Mark> (html:accept-input 'html:submit-button "Submit" :stream stream)))) > > Mark> (defmethod get-form ((url url:http-form) stream query-alist) > Mark> (http:with-successful-response (stream :html) > Mark> (write query-alist :stream stream))) > > Mark> (http:export-url #u"/test.html" > Mark> :html-computed-form > Mark> :form-function #'show-form > Mark> :response-function #'get-form) > > Mark> I understand that makes the POST a little smaller, but for my > Mark> purposes I want all the form variables to appear in the query-alist. > Mark> How can this be done? > >It looks CL-HTTP's form decoding code in HTTP::PARSE-FORM-RAW-VALUES is >written that way. You can work around it like this, but I'm not sure if that >is by design: > >(html:with-fillout-form (:post url :stream stream > :ENCODING-TYPE '(:MULTIPART :FORM-DATA)) > ...) Indeed, no value is represented as nil by the macro bind-query-values. You can look at how this code works and default values the way you like. Consider using the w3p presentation system for higher level and cleaner abstractions.