CGI script problem

Discussion in 'HTML' started by Paul F. Johnson, Oct 11, 2004.

  1. 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
     
    Paul F. Johnson, Oct 11, 2004
    #1
    1. Advertising

  2. Paul F. Johnson

    Jeff Thies Guest

    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
     
    Jeff Thies, Oct 11, 2004
    #2
    1. Advertising

  3. 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
     
    Paul F. Johnson, Oct 11, 2004
    #3
  4. Paul F. Johnson

    Jan Faerber Guest

    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
     
    Jan Faerber, Oct 11, 2004
    #4
  5. Paul F. Johnson

    mbstevens Guest

    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
     
    mbstevens, Oct 11, 2004
    #5
  6. 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 |
    Website | http://www.newtnotes.com

    Drop "PANTS" to reply by email
     
    Jeffrey Silverman, Oct 11, 2004
    #6
  7. Paul F. Johnson

    Jeff Thies Guest

    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
     
    Jeff Thies, Oct 11, 2004
    #7
  8. Paul F. Johnson

    mbstevens Guest

    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/
     
    mbstevens, Oct 11, 2004
    #8
  9. Paul F. Johnson

    Rob McAninch Guest

    Jeff Thies
    <news:ODtad.36$>:

    >> 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
     
    Rob McAninch, Oct 18, 2004
    #9
  10. Paul F. Johnson

    Rob McAninch Guest

    Jan Faerber <news:_Pvad.681$>:

    > 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
     
    Rob McAninch, Oct 18, 2004
    #10
  11. Paul F. Johnson

    Rob McAninch Guest

    mbstevens <news:1twad.166$>:

    > Try to get hold of Elizabeth Castro's
    > "Perl and CGI for the World Wide Web"
    > to bring it all together.


    Careful with that, it doesn't initially use the CGI module for
    parsing forms but rather a home rolled version.

    --
    Rob McAninch
    http://rock13.com Perl Programming and
    Web Stuff: http://rock13.com/webhelp
     
    Rob McAninch, Oct 18, 2004
    #11
  12. Paul F. Johnson

    Guest

    Rob McAninch wrote:

    > mbstevens <news:1twad.166$>:
    >
    >> Try to get hold of Elizabeth Castro's
    >> "Perl and CGI for the World Wide Web"
    >> to bring it all together.

    >
    > Careful with that, it doesn't initially use the CGI module for
    > parsing forms but rather a home rolled version.
    >

    She mentions this herself in the *second* edition, which
    I should also have mentioned. The first edition is outdated.

    --
    mbstevens
    http://www.mbstevens.com
     
    , Oct 18, 2004
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    709
    Michael Sparks
    Jul 30, 2005
  2. Amir  Michail

    cgi relay for python cgi script

    Amir Michail, Oct 4, 2005, in forum: Python
    Replies:
    7
    Views:
    445
    Michael Ekstrand
    Oct 4, 2005
  3. Muzammil
    Replies:
    1
    Views:
    1,182
    red floyd
    Aug 28, 2008
  4. Gavri Savio Fernandez

    cgi = CGI.new causes the script to hang

    Gavri Savio Fernandez, Nov 30, 2003, in forum: Ruby
    Replies:
    2
    Views:
    262
    Ara.T.Howard
    Dec 1, 2003
  5. kath
    Replies:
    4
    Views:
    699
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page