CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Saving and recalling the contents of a perl generated form?

 



Calab
Novice


Sep 10, 2012, 5:40 AM

Post #1 of 6 (1171 views)
Saving and recalling the contents of a perl generated form? Can't Post

Our users have requested that we add a feature to one of our cgi web apps that are written in Perl...

The users fill out a form, and click the submit button to execute a script. They would like to be able to click a button and save the content of the form to their drive, and reload it at a later time.

Is there a method I can use to cram all the data from a submitted form into a single file so that the user can write it to the hard drive... and then reliably parse that file when the user submits the file back to our perl script?


wickedxter
User

Sep 10, 2012, 7:54 AM

Post #2 of 6 (1166 views)
Re: [Calab] Saving and recalling the contents of a perl generated form? [In reply to] Can't Post

Sure, you can use a flat-file or mysql database and SQLite database. Flat-file needs no extra modules but can lead to corruptions over time. MySQL database this needs a server that will run on the web-server to do work. SQLite only needs the modules to work and no extra server running to get it to work and saves the data in a file which can then be downloaded and read by SQLite Database Broswer 2.0 (its basic but works)

My best bet would be to use the SQLite, it just like MySQL but no need for a database server.

http://search.cpan.org/~adamk/DBD-SQLite-1.37/lib/DBD/SQLite.pm


Code
 use DBI; 
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","");



FishMonger
Veteran / Moderator

Sep 11, 2012, 7:04 AM

Post #3 of 6 (1158 views)
Re: [Calab] Saving and recalling the contents of a perl generated form? [In reply to] Can't Post


Quote
They would like to be able to click a button and save the content of the form to their drive, and reload it at a later time.

You want to write the data to file on the client's system? It is possible if you want to write malware.


Quote
and reload it at a later time

Do you mean later in the same session, like when navigating a "shopping cart" to the "checkout", or later as in days or weeks?

If in a shopping cart type of situation, then I'd use server side sessions i.e., the CGI::Session module. http://search.cpan.org/~markstos/CGI-Session-4.48/lib/CGI/Session.pm

If the data is to be retrieved at an unknown future date/time, then use the DBI module to store the data in a database of your choice. My choice would be mysql.
http://search.cpan.org/~timb/DBI-1.622/DBI.pm


Calab
Novice


Sep 12, 2012, 4:58 AM

Post #4 of 6 (1153 views)
Re: [FishMonger] Saving and recalling the contents of a perl generated form? [In reply to] Can't Post

No malware here... It's just data from a form that a user may want to reuse without having to manually fill the form in each time.

When the user clicks a "Save form" button, the form is submitted. The perl script would read the data submitted and enumerate it into a single string/file/??? and then present this enumerated data to the user for download.

When the user clicks a "Load form" button, the file saved earlier would be selected by the user as part of a form and then for form submitted. My script would then take the data submitted by the user and un-enumerate it back into it's individual variables, which would populate the form.

What I'm really looking for is a simple way to enumerate the data from a posted form, so I could create a file that the user would download and save.


FishMonger
Veteran / Moderator

Sep 12, 2012, 7:13 AM

Post #5 of 6 (1150 views)
Re: [Calab] Saving and recalling the contents of a perl generated form? [In reply to] Can't Post

That's an odd and inefficient approach. You should save the data on the server, not the client.

The best way to "enumerate" the data is to store it in a database as we've already mentioned. However, if you wish you could store it in a plain text file. There are a number of ways to format the text file. You could use a standard csv format, or any number of different config formats, such as a standard Windows ini file. There are numerous modules on cpan for reading/writing the config file.

Here are a couple choices.
Config::Tiny - Read/Write .ini style files with as little code as possible - http://search.cpan.org/~adamk/Config-Tiny-2.14/lib/Config/Tiny.pm
Config::INI - simple .ini-file format - http://search.cpan.org/~rjbs/Config-INI-0.019/lib/Config/INI.pm


FishMonger
Veteran / Moderator

Sep 12, 2012, 7:17 AM

Post #6 of 6 (1149 views)
Re: [Calab] Saving and recalling the contents of a perl generated form? [In reply to] Can't Post

Another option would be to use the Storable module to serialize a perl data structure (i.e., a perl hash ref) and save it to disk.

http://search.cpan.org/~ams/Storable-2.39/Storable.pm


(This post was edited by FishMonger on Sep 12, 2012, 7:17 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives