Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

CGI lib question

by hok_si_la (Curate)
on Feb 02, 2005 at 19:13 UTC( #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


      Thanks for the info. I will look into CGI::Simple, and Ovid's CGI course. When looking for more info on CGI::simple vs I found this site for anybody who's interested.

      It also seems to have some very useful methods.
      Thanks again,
        Here is a much better link that compairs the two:
Re: CGI lib question
by holli (Monsignor) on Feb 02, 2005 at 19:48 UTC
    First question: How many thousands of things can go wrong by altering $ENV{QUERY_STRING}?

    holli, regexed monk

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2016-08-30 04:25 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (410 votes). Check out past polls.