What is the best way to get the URL generated by a <FORM>?

Started by Jeremy Reimer, May 19, 2010, 10:39:59 AM

Previous topic - Next topic

Jeremy Reimer

Hi folks,



I'm trying to build a field selector in newLISP.  Right now I have the code:



(define (multi-select-box inputlist)
(let (a "")
(extend a "<form action='multi-select-submit.cgi'")
(dolist (x inputlist)
(extend a "<input type='checkbox' name='input' value='" (string x) "'>" (string x) "<br>"))
(extend a "<input type='submit' value='Submit'>")
(extend a "</form>")
a))


What this function does is return a string that creates a multi-select HTML form (with checkboxes) based on a list.  This string can then be printed to the web page.  When the user clicks "Submit", it redirects to a URL like this one:



http://localhost:8080/multi-select-submit.cgi?input=document&input=element">http://localhost:8080/multi-select-subm ... ut=element">http://localhost:8080/multi-select-submit.cgi?input=document&input=element



Now, from that URL I can probably extract the form values input=document and input=element.  But I'm not sure how to get the current URL in the first place.  



I am using newLISP and Dragonfly to serve the web pages.



Thanks for any help you can provide!

itistoday

I'm not sure I understand your question. But just looking at your code I see that you're using the same name for all the checkboxes. If you want to do that you should put a '[]' after the name like this: 'input[]' so that Dragonfly gets all the values in a list, not just the last one.



Have you looked over these?



http://www.rundragonfly.com/dragonfly_getpost">//http://www.rundragonfly.com/dragonfly_getpost

http://www.rundragonfly.com/locating_self">//http://www.rundragonfly.com/locating_self



Remember, all of the guide is in the example-site folder that comes with Dragonfly, and you're encouraged to also browse through its source to see the source for the guide's pages as well as it's a good way to learn Dragonfly.
Get your Objective newLISP groove on.

Jeremy Reimer

Thanks, it was ($GET) that I was looking for.  I wanted to make a multi-select box and return all elements the user checked.  You were exactly right, I needed to add "[]" to each "input" element, so that I could get back the whole thing as a list.  



So now I have



(define (multi-select-box inputlist)
(let (a "")
(extend a "<form action='multi-select-submit.cgi'")
(dolist (x inputlist)
(extend a "<input type='checkbox' name='input[]' value='" (string x) "'>" (string x) "<br>"))
(extend a "<input type='submit' value='Submit'>")
(extend a "</form>")
a))


and in multi-select-submit.cgi I have:



(println "<br>GET info: " ($GET "input[]"))


And the answer it returns is a list of checked elements, eg: GET info: ("element" "name" "date" "data")



This is exactly what I wanted! Thanks so much!

itistoday

Glad I could help. :-)
Get your Objective newLISP groove on.