Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > CGI script problem

Reply
Thread Tools

CGI script problem

 
 
Paul F. Johnson
Guest
Posts: n/a
 
      10-11-2004
Hi,

I have a very simple form which is supposed to take an entry from the
webpage form and then redirect accordingly.

The form looks like this

<form method="POST" name="cgi/articles.cgi">
<select>
<option value="#" selected>Choose an article...</option>
<option value="overview">Overview</option>
<option value="defining">Defining 'Community' Arts</option>
<option value="whybigisbeautiful">Why Big is Beautiful</option>
<option value="whybigisn't">Why Big isn't Always Beautiful</option>
<option value="whyfilm">Why Film?</option>
<option value="processversusproduct">Process Versus Product</option>
<option value="devisingmethodologies">Devising Methodologies</option>
<option value="leightech">Using Mike Leigh's Techniques</option>
<option value="workingwithnon-actors">Working with Non-Actors</option>
<option value="funding">Funding and Political Perspectives</option>
<option value="conclusions">Conclusions</option>
<option value="authors">About the Authors</option>
</select>
<input type="submit" value="Go!">
</form>

with the cgi script looking like this

#!/usr/bin/perl -wT
use CGI;
use CGI::Carp qw(fatals_to_browser);
use strict;
my($q) = new CGI;
print q->header("Content type: text/html\n\n");
read (STDIN, $input,$ENV{'CONTENT_LENGTH'});
if ($input eq '#')
{
print q->header("Content type: text/html\n\n");
exit;
}
$url = $input + '.html';
print $q->redirect($url);

This should do the redirection for me when someone clicks on the "Go!"
button (unless I've completely messed up somewhere [which is not unknown
;-p]).

I'm trying to rewrite something called cssscriptdict - it's something
revolting you can see if you go to
http://www.smmp.salford.ac.uk/dixonpeters. It looks like an unholy mix
of CSS and JS - I'm trying to vanquish the JS and these scripts.

This cssscriptdict stuff is only ever used for the same dropdown menu on
a number of pages. If I can change it to a #include which can use the
cgi script, then life will be happier (well, it will for me).

So, is the CGI wrong, the form wrong or both?

TTFN

Paul
 
Reply With Quote
 
 
 
 
Jeff Thies
Guest
Posts: n/a
 
      10-11-2004
Paul F. Johnson wrote:
> Hi,
>
> I have a very simple form which is supposed to take an entry from the
> webpage form and then redirect accordingly.
>
> The form looks like this
>
> <form method="POST" name="cgi/articles.cgi">
> <select>
> <option value="#" selected>Choose an article...</option>
> <option value="overview">Overview</option>
> <option value="defining">Defining 'Community' Arts</option>
> <option value="whybigisbeautiful">Why Big is Beautiful</option>
> <option value="whybigisn't">Why Big isn't Always Beautiful</option>
> <option value="whyfilm">Why Film?</option>
> <option value="processversusproduct">Process Versus Product</option>
> <option value="devisingmethodologies">Devising Methodologies</option>
> <option value="leightech">Using Mike Leigh's Techniques</option>
> <option value="workingwithnon-actors">Working with Non-Actors</option>
> <option value="funding">Funding and Political Perspectives</option>
> <option value="conclusions">Conclusions</option>
> <option value="authors">About the Authors</option>
> </select>
> <input type="submit" value="Go!">
> </form>
>
> with the cgi script looking like this
>
> #!/usr/bin/perl -wT
> use CGI;
> use CGI::Carp qw(fatals_to_browser);
> use strict;
> my($q) = new CGI;
> print q->header("Content type: text/html\n\n");


You've just printed a header. The blank line, the second \n signifies
the end of the header.


> read (STDIN, $input,$ENV{'CONTENT_LENGTH'});



> if ($input eq '#')
> {
> print q->header("Content type: text/html\n\n");
> exit;


Another header!

> }
> $url = $input + '.html';
> print $q->redirect($url);


Just read the perl docs on CGI.pm.

Google: perldoc CGI

Or if you have perl on you machine, type that at a command prompt.


What you'll want to do is name your select:

<select name="url">

then:

use CGI;
my $q=new CGI;

my $url=$q->param('url');

unless($url eq '#'){
print $q->redirect($url . '.html');

}

>
> This should do the redirection for me when someone clicks on the "Go!"
> button (unless I've completely messed up somewhere [which is not unknown
> ;-p]).
>
> I'm trying to rewrite something called cssscriptdict - it's something
> revolting you can see if you go to
> http://www.smmp.salford.ac.uk/dixonpeters. It looks like an unholy mix
> of CSS and JS - I'm trying to vanquish the JS and these scripts.
>
> This cssscriptdict stuff is only ever used for the same dropdown menu on
> a number of pages. If I can change it to a #include which can use the
> cgi script, then life will be happier (well, it will for me).
>
> So, is the CGI wrong, the form wrong or both?
>
> TTFN
>
> Paul

 
Reply With Quote
 
 
 
 
Paul F. Johnson
Guest
Posts: n/a
 
      10-11-2004
Hi,

Jeff Thies wrote:
> What you'll want to do is name your select:
>
> <select name="url">
>
> then:
>
> use CGI;
> my $q=new CGI;
>
> my $url=$q->param('url');
>
> unless($url eq '#'){
> print $q->redirect($url . '.html');
>
> }


For some reason, on my access_log, all I'm seeing is the following for
that script...

127.0.0.1 - - [11/Oct/2004:12:14:23 + 0100] "POST
/smmp-new/research/performance/dixonpeters/thearticlespage.html
HTTP/1.1" 200 3568
"http://127.0.0.1/smmp-new/research/performance/dixonpeters/thearticlespage.html"
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626
Firefox/0.9.1

That looks to me that it's posting out the referring page rather than
the page contained in the option value setting.

My httpd.conf file looks fine (and I do have cgi scripts running on it)

TTFN

Paul
 
Reply With Quote
 
Jan Faerber
Guest
Posts: n/a
 
      10-11-2004
Jeff Thies wrote:

> Paul F. Johnson wrote:


>> The form looks like this
>>
>> <form method="POST" name="cgi/articles.cgi">


When is it 'articles.cgi' and when 'articles.pl'?
Isn't it '<form method="post" action="/cgi...">'?

>> #!/usr/bin/perl -wT
>> use CGI;
>> my($q) = new CGI;

....

When do you use brackets - 'my($q) = ...'?
And what is 'q': 'print q->header(...'?



--
Jan

http://213.47.90.11
 
Reply With Quote
 
mbstevens
Guest
Posts: n/a
 
      10-11-2004
Paul F. Johnson wrote:

> read (STDIN, $input,$ENV{'CONTENT_LENGTH'});


Verrrrrrrry strange to try reading from STDIN in a CGI script
to get its data from a user.
You have a form that's creating option data.
In your script you will be using
param(..........) to access the data from that form.

Try to get hold of Elizabeth Castro's
"Perl and CGI for the World Wide Web"
to bring it all together. I also have links
to various sites that have tutorials at
http://www.mbstevens.com/bc.html ...and pull
down form menu and choose CGI/Perl.
--
mbstevens

 
Reply With Quote
 
Jeffrey Silverman
Guest
Posts: n/a
 
      10-11-2004
On Mon, 11 Oct 2004 11:26:19 +0100, Paul F. Johnson wrote:

> So, is the CGI wrong, the form wrong or both?


I haven't looked in detail. However the form is certainly wrong a little
bit at least: No "action="!

Change

<form method="POST" name="cgi/articles.cgi">

to

<form method="POST" action="cgi/articles.cgi">

Assuming, of course, that the name and path of the CGI script is
"cgi/articles.cgi"

There may as yet be problems with the CGI script itself. I didn't look any
deeper as the fundamental problem is that none of the data is getting to
the script!

--
Jeffrey D. Silverman | http://www.velocityreviews.com/forums/(E-Mail Removed)
Website | http://www.newtnotes.com

Drop "PANTS" to reply by email

 
Reply With Quote
 
Jeff Thies
Guest
Posts: n/a
 
      10-11-2004
Paul F. Johnson wrote:

> Hi,
>
> Jeff Thies wrote:
>
>> What you'll want to do is name your select:
>>
>> <select name="url">
>>
>> then:
>>
>> use CGI;
>> my $q=new CGI;
>>
>> my $url=$q->param('url');
>>
>> unless($url eq '#'){
>> print $q->redirect($url . '.html');
>>
>> }

>
>
> For some reason, on my access_log, all I'm seeing is the following for
> that script...



That script has no error checking, a path to perl, or a default if the
option is "#". Add them.

Also, your html paths in your options are relative. So redirects would
be done relative to the script directory.

print $q->redirect('path_to_html' . $url . '.html');

or use a more qualified path in your options.

Jeff


>
> 127.0.0.1 - - [11/Oct/2004:12:14:23 + 0100] "POST
> /smmp-new/research/performance/dixonpeters/thearticlespage.html
> HTTP/1.1" 200 3568
> "http://127.0.0.1/smmp-new/research/performance/dixonpeters/thearticlespage.html"
> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626
> Firefox/0.9.1
>
> That looks to me that it's posting out the referring page rather than
> the page contained in the option value setting.
>
> My httpd.conf file looks fine (and I do have cgi scripts running on it)
>
> TTFN
>
> Paul

 
Reply With Quote
 
mbstevens
Guest
Posts: n/a
 
      10-11-2004
mbstevens wrote:

> Try to get hold of .........


Here's another tutorial that might be exactly what you need
to pull the .html side and the perl side together:
http://www.cgi101.com/book/
 
Reply With Quote
 
Rob McAninch
Guest
Posts: n/a
 
      10-18-2004
Jeff Thies
<news:ODtad.36$(E-Mail Removed) .net>:

>> print q->header("Content type: text/html\n\n");

>
> You've just printed a header. The blank line, the second \n
> signifies the end of the header.


print $q->header; # will do the same thing, the extra \n's are not
necessary and probably inject extra blank lines into the document
for no purpose.

--
Rob McAninch
http://rock13.com Perl Programming and
Web Stuff: http://rock13.com/webhelp
 
Reply With Quote
 
Rob McAninch
Guest
Posts: n/a
 
      10-18-2004
Jan Faerber <news:_Pvad.681$(E-Mail Removed)>:

> Jeff Thies wrote:
>
>> Paul F. Johnson wrote:

>
>>> The form looks like this
>>>
>>> <form method="POST" name="cgi/articles.cgi">

>
> When is it 'articles.cgi' and when 'articles.pl'?


Depends on how you have your server configured. *.cgi is more
common, while *.pl was typically used for perl library files prior
to perl modules.

> Isn't it '<form method="post" action="/cgi...">'?


The action isn't necessary if it submits to itself.

>>> #!/usr/bin/perl -wT
>>> use CGI;
>>> my($q) = new CGI;

> ...
>
> When do you use brackets - 'my($q) = ...'?


In this case the parens around $q is unnecessary. You might do
something like:

my( @array, %hash) = (); # both are initialized empty.

I.e., use parens when the my should include more than one variable,
or if you are trying to force a list context on whatever is right
of the = sign.

> And what is 'q': 'print q->header(...'?


Obviously a typo. $q.

--
Rob McAninch
http://rock13.com Perl Programming and
Web Stuff: http://rock13.com/webhelp
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert exe file of cgi script into .cgi extension. Muzammil C++ 1 08-28-2008 07:50 PM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
cgi relay for python cgi script Amir Michail Python 7 10-04-2005 07:11 PM
Python-cgi or Perl-cgi script doubt praba kar Python 1 07-30-2005 08:25 AM
cgi = CGI.new causes the script to hang Gavri Savio Fernandez Ruby 2 12-01-2003 05:37 AM



Advertisments