Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Editing Posted Data

by neniro (Priest)
on Jul 08, 2005 at 08:07 UTC ( #473358=note: print w/replies, xml ) Need Help??


in reply to Editing Posted Data

First off all I suggest you to use HTML::Template or one of the other popular templating systems to separate code from content. You print a table for each record you receive - maybe it would be better to print just new table-rows for each of them. If you want your users to be able to edit those recordsets again you could create a html-form for each recordset, display them in input-tags and add a submit button. Based on the action you receive via CGI your script will display/add or edit records.

UPDATE:

An example CGI app of my own to show you a way to structure such an app:

#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw ( warningsToBrowser fatalsToBrowser ); use DB::Countries; use Templating::Countries; use Query::Countries; # # declaration # my $q = new CGI; my $form = $q->Vars(); my $db = new DB::Countries; my $tmpl = new Templating::Countries; my $dispatch = { 'search' => sub { my $query = new Query::Countries ($form); $tmpl->overview($db->get($query)); }, 'edit' => sub { $tmpl->edit($db->get($form->{'id'})); }, 'new' => sub { $tmpl->add(); }, 'delete' => sub { $tmpl->del($db->get($form->{'id'})); }, 'update' => sub { $db->update($form); $tmpl->default(); }, 'insert' => sub { $db->insert($form); $tmpl->default(); }, 'remove' => sub { $db->remove($form->{'ID_country'}); $tmpl->default(); }, 'default' => sub { $tmpl->default() }, }; # # main # print $q->header(); print $dispatch->{$form->{action}} ? $dispatch->{$form->{action}}() : $dispatch->{'default'}(); exit;
You can see that the app is reduced to a dispatch and just a few lines of code. Everything else is seperated in modules. One for all database-action, one for building queries and one for the templating. Based on the $form->action it receives it calls the related actions using the dispatch table.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-02-05 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (32 votes). Check out past polls.

    Notices?