Gossamer Forum
Quote Reply
timestamp problem
i want to use timestamp field type to date an entry when i add a new record AND when i modify a record. i tried the code shown below in section commented 12/09/2010. it works fine in adding and modifying records. however, it messes up all the search forms -- if i search, my timestamp field is set to current time in the query. i don't want to use timestamp field in the query! i tried setting the value if in the add form, but it doesn't recognize that condition in get defaults sub. how can i determine that i'm adding a record?

Code:
sub _get_defaults {
# -------------------------------------------------------------------
# Returns default values for fields. Bases it on what's passed in,
# cgi input, def file defaults, otherwise blank.
#
my $self = shift;
my @cols = $self->{db}->ordered_columns;
my $c = $self->{cols};
my $values = {};
foreach my $col (@cols) {
my $value = '';
if (exists $self->{values}->{$col}) { $value = $self->{values}->{$col} }
### 12/09/2010 this causes search forms to use current time as value to match, thus no records found
elsif ($c->{$col}->{type} =~ /TIMESTAMP/) {
## elsif (($self->{add_form}) && ($c->{$col}->{type} =~ /TIMESTAMP/)) {
$value = $self->_get_time($c->{$col});
}
###
elsif (exists $self->{input}->{$col}) { $value = $self->{input}->{$col} }
elsif ($self->{defaults} and exists $c->{$col}->{default}) {
if ($c->{$col}->{type} =~ /DATE|TIME|YEAR/) {
($c->{$col}->{default} =~ /0000/)
? ($value = $self->_get_time($c->{$col}))
: ($value = $c->{$col}->{default});
}
else {
$value = $c->{$col}->{default};
}
}
elsif ($self->{defaults} and $c->{$col}->{type} =~ /DATE|TIME|YEAR/) {
$value = $self->_get_time($c->{$col});
}
if ($c->{$col}->{form_type} and uc $c->{$col}->{form_type} eq 'FILE' ) {
$values->{$col."_filename"} = $self->{values}->{$col."_filename"};
}

$values->{$col} = $value;
}
return $values;
}
Subject Author Views Date
Post timestamp problem delicia 4562 Dec 9, 2010, 9:39 AM