Creating an html form

Q&A's, tips, howto's
Locked
joejoe
Posts: 173
Joined: Thu Jun 25, 2009 5:09 pm
Location: Denver, USA

Creating an html form

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

Code: Select all

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/artf ... l-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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Creating an html form

Post by cormullion »

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

Code: Select all

#!/usr/local/bin/newlisp
(load "cgi.lsp")
(println (string "Content-type: text/html\r\n\r\n" 
[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 here.

joejoe
Posts: 173
Joined: Thu Jun 25, 2009 5:09 pm
Location: Denver, USA

Re: Creating an html form

Post by joejoe »

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?ti ... e_Internet

Much appreciated, as always.

Locked