Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Decode CGI with checkboxes

 [1/4] from: rebol::keithdevens::com at: 16-Sep-2000 23:12

Hi, just wondering how you deal with checkboxes when doing CGI. if you do something like: cgi-data: make object! decode-cgi system/options/cgi/query-string you lose multiple values with the same name, like you'd have in the case of multiple selected checkboxes. I couldn't find anything about it in Rebol: The Official Guide. I did a search in all the code on the book's CD and found something that can aid you in generating the HTML for form elements, but nothing that lets you read them. Also, the example in Rebol's howto uses a checkbox, but only one! :) Anyone have any solutions? Thanks! Keith

 [2/4] from: sterling:rebol at: 17-Sep-2000 13:58

Just don't make the object and scan the block yourself: decode-cgi "foo=10&foo=20" == [foo: "10" foo: "20"] ; your data is intact parse decode-cgi "foo=10&foo=20" [ some [ copy wrd set-word! copy value string! (print ["Name:" wrd "Value:" value]) ] ] So instead of printing them out you can do something with the values you get for each word. The suggestion to use make object! with decode-cgi just makes handling most data very easy. In the less frequent cases you may have to do a little work yourself. Sorry. Sterling

 [3/4] from: tim:johnsons-web at: 17-Sep-2000 13:30

Hi Keith: Send me an email directly if you wish and I'll send you a library I've written and it addresses some of those problems. An older version of that is on the rebolforces web page. I'm on my way out the door right now and will have more time later..... Regards -Tim [rebol--keithdevens--com] wrote:

 [4/4] from: g:santilli:tiscalinet:it at: 18-Sep-2000 19:59

Hello [rebol--keithdevens--com]! On 17-Set-00, you wrote: r> Hi, just wondering how you deal with checkboxes when doing r> CGI. The CGI decoder built in YARWeS worked in this case. Let me see if I can dig it back... Hmm... perhaps it's a bit complicated, anyway: insert-no-dups: func [ list [any-block!] word [word!] value [any-type!] /local pos ] [ either found? pos: find head list to-set-word :word [ either list? second pos [ append second pos value ] [ change/only next pos to-list reduce [second pos value] ] ] [ append list reduce [to-set-word :word value] ] head list ] uchar: [unreserved | escape] unreserved: make bitset! #{000000009277FF03FEFFFFFFFFFFFF7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} escape: [#"%" 2 HEX] HEX: charset "0123456789ABCDEFabcdef" query-allowed: charset ";/?:@+" last-query-name: none last-query-value: none last-query-object: make list! [] namevalue: [ copy last-query-name some [uchar | query-allowed] #"=" copy last-query-value some [uchar | query-allowed] [#"&" | CRLF | end] (insert-no-dups last-query-object to-word decode last-query-name decode last-query-value) ] query-rule: [(last-query-object: make list! []) some namevalue end] decoded-string: copy "" last-string: none last-hex: none filter: func [str] [either none? str [""] [str]] decode-rule: [[ some [copy last-string to #"%" skip copy last-hex 2 HEX ( append decoded-string join filter last-string hex2char last-hex )] | none ] copy last-string to end (append decoded-string filter last-string) ] decode: func [ string [any-string!] ] [ decoded-string: copy "" string: translate copy string #"+" #" " if not parse/all string decode-rule [ throw make error! reduce [ 'user 'message "Decode error" "Error decoding url-encoded string" string ] ] decoded-string ] parse-query: func [string [string!]] [ parse/all string query-rule make object! to-block head last-query-object ] I just did some cut&paste, so probably it won't work. Anyway, you could even continue using DECODE-CGI:
>> blk: decode-cgi "name=value1&name=value2&name=value3"
== [name: "value1" name: "value2" name: "value3"]
>> fixed: []
== []
>> foreach [name value] blk [
[ either pos: find fixed :name [ [ pos/2: compose [(pos/2) (value)] [ ] [ [ insert insert fixed :name value [ ] [ ] == [name: ["value1" "value2" "value3"]] HTH, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila --