HTML form to cgi help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HTML form to cgi help
# 1  
Old 09-23-2005
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.
# 2  
Old 09-23-2005
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.

Code:
#!/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).
# 3  
Old 09-23-2005
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:
Code:
#!/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)
# 4  
Old 09-23-2005
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?
# 5  
Old 09-23-2005
Thanks!

Now I just need ot figure out the variable passed.
# 6  
Old 09-23-2005
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).
# 7  
Old 09-23-2005
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:

https://www.unix.com/shell-programming-and-scripting/16766-perl-variable-input-via-html-post62175.html#post62175
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run command through html+cgi in bash

Hi everyone, I want to kill process through the web, so I create html page with single bottom that run kill command in shell script with CGI. Here is html code: <td><form METHOD="GET" action="http://IP:port/cgi_bin/script.cgi" > <input type="submit" value= "Submit" > <INPUT name="q"... (7 Replies)
Discussion started by: indeed_1
7 Replies

2. Shell Programming and Scripting

Cgi to dump xml data from form input field

Hi All, I am trying to write a shell script which takes parse the web form find the input field and dump the data of that field into one xml file. The form looks like, <input type="button" id="btnSave" value="Save" onclick="saveXmlData()"/> <form name="submitForm"... (1 Reply)
Discussion started by: jdp
1 Replies

3. Shell Programming and Scripting

pass argument to html upload form

I am using an html form and a php upload script to upload files. HTML form <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table... (1 Reply)
Discussion started by: anil510
1 Replies

4. Solaris

man pages in html form

Hi I would like to convert standard online man pages from my solaris10 system into html form to publish it on my webpage. How this can be done in Sol10 ? thx for help. (2 Replies)
Discussion started by: presul
2 Replies

5. Web Development

in cgi perl script a form

hi,i hav a form in cgi perl script.this script accepts a value from user from another html form, and depending upon this value,i need to disable /enable radio buttons in cgi-perl script wen second page is displayed on executing cgi perl script.how do i do it using javascript? (0 Replies)
Discussion started by: raksha.s
0 Replies

6. Shell Programming and Scripting

cgi script to echo a html file

Hi, I'm learning some simple cgi scripting. I can make a script like this, so my browser shows "Hello World" /www/cgi-bin/name.sh --- #!/bin/sh MyName=World echo "<html> Hello $MyName </html>" --- What I'd like is to have a separate html and script files in the cgi folder so ... (1 Reply)
Discussion started by: Performer
1 Replies

7. Shell Programming and Scripting

perl cgi form action target

Hello All, I was trying to come up with a form using perl cgi. I then created a frame to show the output of the form. Refer below print $display_form->start_form(-title=>"Updateuser", -style => 'font-size: 9pt; color: #202020 ; font-family: Verdana', action=>"${DOCROOT}updateUser.pl",... (4 Replies)
Discussion started by: garric
4 Replies

8. Shell Programming and Scripting

html - df -k cgi script

Hey - I am new to cgi scripting... just writing a script to output df -k output to html page... but I cannot get the df lines on separate lines on the page, it all comes out on one line and is not very readable.. any suggestions? My script is below - please keep in mind I am only new to it so... (1 Reply)
Discussion started by: frustrated1
1 Replies

9. Shell Programming and Scripting

Passing FORM(HTML) variable to ksh

I am currently able to use the $QUERY_STRING variable and simply cut out what I need to be assigned as variables within the shell script. However, I've been able to use the "name" value assigned within the FORM(HTML) as a variable when I use perl. Why is it that ksh doesn't read the "name" in as... (1 Reply)
Discussion started by: douknownam
1 Replies

10. UNIX for Dummies Questions & Answers

HTML-CGI on Unix

AAAHHH!! I've made a perl program that you can run on a web browser. This program needs to be run everyday, and I don't want to have to run it everyday. The problem is when I try running the program from my terminal, all it does is print stuff to the terminal page (the program involves a lot of... (4 Replies)
Discussion started by: sstevens
4 Replies
Login or Register to Ask a Question