Solved

CGI Script with KSH to accept form input

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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article will show, step by step, how to integrate R code into a R Sweave document
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

710 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