Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

CGI lib question

by hok_si_la (Curate)
on Feb 02, 2005 at 19:13 UTC ( [id://427379]=perlquestion: print w/replies, xml ) Need Help??

hok_si_la has asked for the wisdom of the Perl Monks concerning the following question:

Greetings again wizards of the web,

I have just migrated all of my forms over to use the CGI lib. Several of them work in the following manner: form 'A' -> script 'B' onclick list element -> form 'C'.

For clarification hers is an example. Search for all servers in Texas (form A) yields 30 servers in a list (script B). When one of these servers is clicked form C is displayed which shows the selected server information which can be edited by an admin.

Now the problem. Form C will have defaults for most all fields that are not in use. This means that in order to populate the form elements with the values from my SQL table, I need to pass them through CGI headers. That would not be a problem if I weren't using tab functions that allow users to navigate back and forth from one site to another.

I noticed that I can use the unescape() utility in the following fashion:
$ENV{QUERY_STRING}=unescape($ENV{QUERY_STRING});  #--Needed for form element population.
This actual populates the elements with the correct value when the invoking script escapes a URL string to allow for textarea formatting.

First question: How many thousands of things can go wrong by altering $ENV{QUERY_STRING}?

Second Question: If it is okay to use the above statement then I can effectively populate the form elements by creating a string from my table query and setting it to $ENV{QUERY_STRING}. Otherwise Is there a function in the CGI lib that I overlooked that accommodates both element default values and element values?

Replies are listed 'Best First'.
Re: CGI lib question
by legato (Monk) on Feb 02, 2005 at 19:29 UTC

    Firstly, I highly suggest CGI::Simple -- it should be a drop-in replacement for CGI, and therefore relatively painless.

    Second, read the docs for the above (depending on which you decide to use). One can modify parameters through the param function in CGI::Simple, for example. I would try to refrain from modifying %ENV directly.

    Also, the %ENV represents the environment for your script -- if you do change it (even if it is through use of param()), as soon as your script ends those changes will be lost. The two main ways to pass data around between CGI scripts are sessions and parameters.

    Parameters are relatively easy -- especially by making use of the HTML hidden input type:

    <input type='hidden' name='my_hidden_var' value='some data here' />
    However, you will have to be sure that these parameters will be passed by the browser -- which means every link is a form submission.

    Sessions can be implemented a number of ways. The easiest (also the most prone to problems) is to simply set cookies for the values you need to pass around. One can replace or combine this method with file- or database-driven session management, if need be. I highly suggest looking at Ovid's CGI course, which covers such things and points to many useful resources.

    Anima Legato
    .oO all things connect through the motion of the mind

      Legato,

      Thanks for the info. I will look into CGI::Simple, and Ovid's CGI course. When looking for more info on CGI::simple vs CGI.pm I found this site for anybody who's interested.
      http://search.cpan.org/src/JFREEMAN/Cgi-Simple-0.077/cgi-simple_vs_cgi-pm.html

      It also seems to have some very useful methods.
      Thanks again,
      hok_si_la
        Here is a much better link that compairs the two:

        http://www.enstimac.fr/Perl/perl5.8.5/site_perl/5.8.5/CGI/Simple.html#differences_from_cgi_pm
Re: CGI lib question
by holli (Abbot) on Feb 02, 2005 at 19:48 UTC
    First question: How many thousands of things can go wrong by altering $ENV{QUERY_STRING}?
    42

    holli, regexed monk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://427379]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-18 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found