Solved

CGI Script with KSH to accept form input

Posted on 1997-05-02
2
799 Views
Last Modified: 2013-12-25
Hi,

I plan to prototypet CGI with KSH.  I need help on how to implement it.!

I plan to test with a very small experiment.  A HTML form take LAST_NAME and FIRST_NAME.  How the flow of the script should be so that when user click the submit button can activate another script (also, how this script or C program get the reponse strings on FORM?) to record the string?

Any sample code provided is greatly appreciated!

Thank you

John
0
Comment
Question by:jma050197
2 Comments
 
LVL 2

Accepted Solution

by:
Philippe earned 100 total points
ID: 1827964
Hi jma,

Here is a sample ksh script that will get first_name and last_name when called and that will add them to a name list.

#!/bin/ksh
echo "Content-type: text/html"
echo ""

#get the different variables out of the query_string

eval `echo $QUERY_STRING | sed -e 's/'"'"'/%27/g' | \
      awk 'BEGIN{RS="&";FS="="}
          $1~/^[a-zA-Z][a-zA-Z0-9_]*$/ {
          printf "QS_%s=%c%s%c\n",$1,39,$2,39}' `

echo $QS_last_name $QS_first_name >> namelist

cat <<EOF
<html><body>
<H2> thank you, ${QS_first_name}, for your results
</body></html>
EOF


Now here is a sample html document with the corresponding form which will send the info to the cgi-script:

<html>
<body>
<form action="http://www.myserver/cgi-bin/demo"
  method="GET">
first name: <input type="text" name="first_name" size=20><BR>
last name: <input type="text" name="last_name" size=20><BR>
<input type="submit" name="done" value="submit">
</form>
</body>
</html>


Make sure to put your script into the cgi-bin directory of your server (in the example the file name of the script is demo) and change the html document so that it points to the script on your server (in the action= part)

Basically what happens is that the cgi-bin is called with the arguments first_name and last_name put in an environment variable called QUERY_STRING. The cgi script can then parse this variable and do whatever is needed. Note that if your cgi script was a C program it could get the value of QUERY_STRING by doing a

args = getenv("QUERY_STRING");

If you want to know more about this consult

http://hoohoo.ncsa.uiuc.edu/cgi/overview.html for example

  hope this helps,

     Philippe


0
 

Author Comment

by:jma050197
ID: 1827965
This is exact help I need!  Thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question