Solved

CGI Script with KSH to accept form input

Posted on 1997-05-02
2
795 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
Comment Utility
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
Comment Utility
This is exact help I need!  Thank you.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now