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

Q&A's, tips, howto's
Locked
Jeremy Reimer
Posts: 19
Joined: Thu May 13, 2010 5:36 pm

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

Post by Jeremy Reimer »

Hi folks,

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

Code: Select all

			(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-subm ... ut=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
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

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

Post by 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/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
Posts: 19
Joined: Thu May 13, 2010 5:36 pm

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

Post by 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

Code: Select all

			(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:

Code: Select all

(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
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

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

Post by itistoday »

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

Locked