ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am wrinting one CGI script.
The HTML screen it creates has 2 elements on it (1 text box and 1 submit button).
In the "form" I am using POST method.
The problem is that, when I click on the submit button the variables for text box and the submit button are not getting posted.
I checked it by inserting the command "export > /tmp/environment" command in the CGI script that I am calling from the browser.
The variables that are supposed to be posted should be part of the environment and should appear in the file /tmp/environment. But
I could not find them in this file.
However, If I use GET method then I could see the variables and their values in the QUERY_STRING variable.
Can anybody suggest why this is happening and am I missing something here?
I belive that data transfer with the POST method is available to the CGI on its STDIN, not in the environment. Try reading STDIN, until eof().
--- rod.
the problem is, that the stdin comes in as one long line
like:
Code:
text_box=hello&submit_btn=OK
but has no terminating linefeed, hence the read never
completes.
I would strongly advise maybe using perl's CGI module as it's much safer than trying yourself.
Still here is a solution of sorts...
(I've tidied up those horrible echoes
Code:
#!/bin/bash
cat <<EOF
Content-type: text/html
<html>
<head>
<title>Test CGI!</title>
</head>
<body>
<form name=INPUT_FORM method=POST action=test.cgi>
Enter any text :
<input type=text name=text_box size=16>
<input type=submit value=OK name=submit_btn>
</form>
EOF
IFS=\& # ampersands that delimit parameter=value pairs
set -- `cat` # a trick to assign pairs to $@ variables
for x;do
var=${x%=*}
val=${x#*=}
echo "<p>$var is:$val</p>"
done
cat << EOF
</body>
</html>
EOF
exit 0
Last edited by bigearsbilly; 05-04-2007 at 03:45 AM.
Thanks for your reply. Its working fine. But I still think there is some other way by which we can directly read the values of the respective variables.
Thanks for your reply. Its working fine. But I still think there is some other way by which we can directly read the values of the respective variables.
If you think about it, in your scenario, how could the second argument ever get read? If the argument list is separated by eofs, then only the first argument could ever get read. Alternatively, the argument list is separated by '&'s, which is left up to your code to interpret. When the data is a stream, you can only ever read it all, and then break it up as appropriate.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.