Monday 15 June 2009

HTML forms & CGI C-Shell scripting

HTML forms are used to select different kinds of user input (Here's a quick tutorial). For example, open your favourite text editor, copy-paste the commands from listing 18.6. HTML -- Form processing example from here) and save the file as text.html.

Then from your browser, open the file to see what the form looks like. It should look like this:


Reading the form data from your shell script is a bit more tricky. You will probably have encountered html pages that look like http://www.someaddress.com/somescript.cgi?param1=value1&param2=value2

value1 and value2 are the parameters that your HTML form has submitted when you hit the submit button (assuming your form only has 2 parameters).

To read them in your c-shell cgi script, use
set input = $<>param1=value1&param2=value2)

so then you will have to split the string and read the parameters individually in different variables:
set param1 = `echo $input | cut -d '&' -f1 | cut -d '=' -f2`
and the same for param2.



0 comments: