Creating an html form

Started by joejoe, June 17, 2012, 11:13:02 PM

Previous topic - Next topic

joejoe

Hi,



I would like to create an html form on my index.cgi.



For example, I would like to have a search on my site and use the term searched for to build my page.



Do I just create the form html, and have it post to mysite.com/index.cgi?search=xyz ?



What do I need to do inside of index.cgi in order to be able to receive a search?



This is not a search engine for searching the content on my site.



I will take the search term and build the page once I know what they are searching for.



I see this in Web.lsp:


Web:get
syntax: (Web:get str-key)

Returns the value of str-key in the query string or nil if not present. If str-key is not provided, returns an association list of all GET values.

Web:post
syntax: (Web:post str-key)

Returns the value of str-key in the client-submitted POST data or nil if not present. If str-key is not provided, returns an association list of all POST values.

http://scruffythinking.com/storage/artful/artful-web.html">http://scruffythinking.com/storage/artf ... l-web.html">http://scruffythinking.com/storage/artful/artful-web.html



If I get my form to submit to xyz.com/index.cgi?search=test then Web:get or Web:post will be able to interpret "test" and be able to doing things with it inside index.cgi?



Okay and thanks! :-)

cormullion

#1
The simplest search form is probably something like this, although this uses cgi.lsp rather than web.lsp.


#!/usr/local/bin/newlisp
(load "cgi.lsp")
(println (string "Content-type: text/htmlrnrn"
[text]<!doctype html>
<html>
 <head>
 <title>Title</title>
 </head>
<body>
[/text]))

(set 'search-string (CGI:get "userinput"))

(println (format [text]
    <form name="form" class="dialog" method="GET">
         <fieldset>
             <input type="text" value="search" name="userinput" >
             <input type="submit" style="display:none"/>
         </fieldset>
    </form>[/text]))

(unless (nil? search-string)
    (println " I couldn't be bothered to search for "" search-string """))

(println [text]
  </body>
</html>
[/text])


as running http://newlisper.nfshost.com/">here.

joejoe

#2
Biggest thanks cormullion! :D



That post was so helpful I added it to your newLISP Wikibook on "The Internet".



https://en.wikibooks.org/w/index.php?title=Introduction_to_newLISP/The_Internet">https://en.wikibooks.org/w/index.php?ti ... e_Internet">https://en.wikibooks.org/w/index.php?title=Introduction_to_newLISP/The_Internet



Much appreciated, as always.