Solved

CGI Script with KSH to accept form input

Posted on 1997-05-02
2
810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
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…
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

628 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