http://qs1969.pair.com?node_id=473358


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.