Solved

CGI Script with KSH to accept form input

Posted on 1997-05-02
2
803 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 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