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

Ok I know I have asked this question before under my replies, but I really haven't got to my answer, so here is a very detailed explanation of what I want to do :

Ok we first start out with a form much like this one -

<form method="post" action="test.cgi"> Server Address :<input type=text name="server_address" size=30> <br> Use Secure Server :<input type=text name="use_secure_server" size=2 ma +xlength=3 value="no"><br> Secure Server Domain :<input type=text name="secure_server_domain" siz +e=30> <br> Secure Server Address :<input type=text name="secure_server_address" s +ize=30> <br> Secure Cgi Directory :<input type=text name="secure_cgi_directory" val +ue="/cgi-bin" size=30><br> Secure CSS Directory :<input type=text name="secure_css_directory" val +ue="/" size=30> <br> Secure Image Directory :<input type=text name="secure_image_directory" + value="/images" size=30><br> Secure Script Directory :<input type=text name="secure_script_director +y" value="/" size=30> <br> Use CgiWrap :<input type=text name="use_cgiwrap" value="no" size=3 max +length=3> <br> CgiWrap Directory :<input type=text name="cgiwrap_directory" value="/c +gi-sys/cgiwrap/demostore" size=30> <br> Cgi Directory :<input type=text name="cgi_directory" value="/cgi-bin" +size=30> <br> <input type=submit value=Save> </form>

Then when the information is submitted it is then placed in a file called test.cfg, which now looks like this :

$server_address = '';
$use_secure_server = 'no';
$secure_server_domain = '';
$secure_server_address = '';
$secure_cgi_directory = '/cgi-bin';
$secure_css_directory = '/';
$secure_image_directory = '/images';
$secure_script_directory = '/';
$use_cgiwrap = 'no';
$cgiwrap_directory = '/cgi-sys/cgiwrap/demostore';
$cgi_directory = '/cgi-bin';

Ok now that information is stored inside of the cfg file so that another script can use it for it's replacement values. Now here is the problem that I have. Lets say that I want to go back to the form and update whats in the cfg file. Ok when I go back to the form I want to see what I entered in the input boxes before, so I only have to make changes to what I want to be updated. How do I get the form to read what has already been entered before out of the cfg file? I would really appreciate any help if possible. If you would like, you can send me an email to jmoore@netphase.net. Thanks once again for your help.

Jonathan

Replies are listed 'Best First'.
Re: form to data to form
by chromatic (Archbishop) on Apr 24, 2000 at 02:16 UTC
    Here's how I would design this:
    • Check for the existence of the cfg file
    • If it exists, read values out of it into a hash (field name => value)
    • Otherwise, initialize the hash with default values
    • Build the form from the hash -- you'll want to change the value= bits of your form to refer to the hash values, instead of having the data hardcoded
    That should get you started. Good luck.
Re: form to data to form
by raflach (Pilgrim) on Apr 24, 2000 at 23:35 UTC
    One point to make on the above answer. From what I can tell, you need 2 perl scripts. One that generates the form on the fly, pulling default values from your test.cfg file, and one that is the action of your form, that populates the test.cfg, and or does something else with the data as well. You could probably do it all in a single script, by checking to see how your script was called, ie with or without params, but it might be less confusing for you to use two.

    The key is to generate your form from a script that can look at your config file. HTML cannot look at your config file, nor can javascript.
      I think chromatic's way, with a single script, would be much easier. A strange script, at any rate....