Gossamer Forum
Home : Products : DBMan SQL : Development, Plugins and Globals :

Split Form Input Plugin

Quote Reply
Split Form Input Plugin
Hi,

The following question is part of another thread in the main DBManSQL section but I haven't had any feedback yet. As it relates to a plugin, I thought that I would start a new thread here incase anyone tries to do the same thing in the future.

I'm writing a plugin that splits dates entered as 01/21,02/05,03/27,04/30,etc... in one form field and adds them to the database as individual dates.

I got the plugin working using the sub below but I am not sure about how to handle the add_success part indicated in red. It works with (1) but I'm not sure what I should really use. The Home.pm add_record sub uses $self->add_success($ret); where $ret return 1. I'm assuming that the 1 means that the record was added successfully. What can I use to make sure that ALL my records were added successfully????

Any ideas?

Thanks.

Simon.



sub split_add_record {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'add_record'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my ($self) = @_;
# Do something useful here
# Ignores the plugin if this is not contact table
($self->{cgi}->{db} ne 'public_holiday') and return @_;
GT::Plugins->action ( STOP );
#----------------------------------------------------------------------

my $splitdate;
my @dates = split ',', $IN->param('public_holiday_202');
foreach $splitdate (@dates) {

$self->{cgi}->{public_holiday_202}=$splitdate;


#----------------------------------------------------------------------
return $self->home($self->_language('PER_ADD')) unless ( $self->{user}->{add_p} );

#------------demo code----------------


# add data to related table
return $self->sadd_record() if ( $self->{cgi}->{sdb} and $self->{cgi}->{sdo} );



# Turn arrays into delimited fields
$self->format_insert_cgi;
if ( $self->{cfg}->{'auth_user_field'} ) {
$self->{cgi}->{$self->{cfg}->{'auth_user_field'}} = $self->{user}->{'Username'};
}

# Check foreign keys
my $msg = $self->_check_fk();
($msg) and return $self->add_form($msg);


# Setup the language for GT::SQL.
local $GT::SQL::ERRORS->{ILLEGALVAL} = $self->_language('ADD_ILLEGALVAL');
local $GT::SQL::ERRORS->{UNIQUE} = $self->_language('ADD_UNIQUE');
local $GT::SQL::ERRORS->{NOTNULL} = $self->_language('ADD_NOTNULL');

if ( defined (my $ret = $self->{db}->add($self->{cgi})) ) {



$self->auth_logging('add record ') if ( $self->{cfg}->{log_file} );

#------------demo code-----------


#Don't call up the success page
###$self->add_success($ret);
}
else {
local $^W;
my $error = $GT::SQL::error;
$error =~ s/\n/<br>\n<li>/g;
$self->add_form("<font color=red><ul><li>$error</ul></font>");
}

#end for
}


$self->add_success(1);

#end sub
}

# Always end with a 1.
1;
Subject Author Views Date
Thread Split Form Input Plugin jai 7829 Jan 30, 2003, 8:43 PM
Post Re: [jai] Split Form Input Plugin
jai 7690 Feb 4, 2003, 8:51 PM
Thread Re: [jai] Split Form Input Plugin
jean 7674 Feb 7, 2003, 11:41 AM
Post Re: [jean] Split Form Input Plugin
jai 7651 Feb 7, 2003, 5:35 PM
Thread Re: [jean] Split Form Input Plugin
jai 7640 Feb 9, 2003, 6:49 PM
Thread Re: [jai] Split Form Input Plugin
jai 7612 Feb 16, 2003, 9:59 PM
Post Re: [jai] Split Form Input Plugin
jai 7614 Feb 17, 2003, 11:48 PM
Thread Re: [jean] Split Form Input Plugin
jai 7579 Feb 21, 2003, 3:54 PM
Thread Re: [jai] Split Form Input Plugin
jean 7578 Feb 21, 2003, 4:20 PM
Thread Re: [jean] Split Form Input Plugin
jai 7573 Feb 21, 2003, 5:34 PM
Post Re: [jai] Split Form Input Plugin
jai 7476 Mar 3, 2003, 9:59 PM