HTML form to cgi help

I wrote a script to automate user account verification against peoplesoft. Now I want to make it available to my peers via the web. It is running on Solaris.

I have the form written, but am not sure how to make it work. I think the form should call a perl cgi when submitted. The cgi should call my shell script in the background (cgi-bin/myscript.cgi $email $system &), and present a "task submitted" page. I can write the task sumitted page cgi.

The problem is I am not sure how to manipulate the data posted into the form and pass it to the script. There are three fields. Two need to be passed to the shell script called from the cgi as $1 (email) and $2 (system) variables. The third field (usernames) needs to be written to a text file.

The form can be seen at: http://chuckb.1le.net/tmp/form_test.htm

Any help would be appreciated.

It doesn't have to be perl - can be a simple shell script. But that's up to you.

The form will send all the 'data' into QUERY_STRING variable - you just have to read it and separate each field (should be delimited with the & character) with each field having variable=input such as EMAIL=this&SYSTEM=that.

If you write a simple script you can see the results.

#!/bin/ksh
#
#
echo "Content-type: text/html"
echo
#
full_string="$QUERY_STRING"
echo " <BODY>"
echo " <pre>"
echo "$QUERY_STRING"
echo "</BODY>"
exit

Once you see the results, build the script out to actually perform the same actions as the original web page (form_test.htm) by using echo statements to build the page and normal scripting to run the things you want to run (like splitting QUERY_STRING, moving the 3rd piece into a file (which I don't see that 3rd piece in your code).

The form is calling the cgi, which has 755 permissions. But I am getting a 500 internal server error.

The cgi prints useable html when ran by hand.

This is what the test cgi looks like:

#!/bin/bash

full="$QUERY_STRING"

echo " <html> "
echo " <head> "
echo " <meta http-equiv=Content-Type content=text/html> "
echo " </head> "

echo " <body> "
echo "$full"
echo " </body> "
echo " </html> "
exit

I fixed the form so it has 3 parts (but did not upload it)

I believe you've missed the Content-Type header. Not the HTTP-Equiv one, but the real header one, which is required by most CGI-powered Web servers by default.

Try to put this at the top of the script.

echo -e "Content-Type: text/html\n\n"

And try to get more information if you post again. The part of the Apache error log maybe which describes the error rather than the generic "Internal Server Error" message. And you're sure your Web server really is taught to interpret shell scripts as CGI scripts properly?

Thanks!

Now I just need ot figure out the variable passed.

If I put GET in the form for the method, it works by setting QUERY_STRING to the values, but I cannot use a lot of values.

If I change it to POST, I cannot find the values. I understand POST works better for large numbers of values as it does not put them in the URL, but the values do not get passed as environment variables (I put env in the cgi).

According to the CGI specification, POST form values will be passed to the script via the standard input. So, just read everything from the standard input (with read command?)

Yes you can develop CGI scripts in shell script but you may not find it convenient to always do all that splitting, unescape of special characters (%XX and related stuff) yourself. Perl has modules that allow you to just give the name of the parameter and then get the extracted field value immediately. A past example I posted:

http://www.unix.com/showthread.php?p=62175\#post62175

Thanks. v0.1 is working :slight_smile: