Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Altering fields when adding record

Quote Reply
Altering fields when adding record
Alex,

if I wanted to pre-process some of the data sent from an add form (admin or user) before putting the fields in the database, where would I do that?

Let's say I have a field "Timage" and I want to process it to get (or verify) the ht/width of it before inserting it. Those fields in the table are THeight and TWidth

Where in the routine would I go to verify them, and how would I pull them out --

for example, my "URL" is really a link to an image, and $TImage is it's thumbnail. The following code needs to go into the ADD and MODIFY code somewhere, I'm just not sure where.

$TImage = &process_image($URL); ## Check for and if necessary create Thumbnail
$TWidth = &Image_Width($TImage); ## get width and assign to database
$THeight = &Image_Height($TImage); ## get height and assign to database

Thanks...

Robert


[This message has been edited by pugdog (edited July 20, 1999).]
Quote Reply
Re: Altering fields when adding record In reply to
Hi,

You would need to do that in add.cgi for the user, and admin.cgi for the admin. In add.cgi:

Code:
# Validate the form input..
$rec = &cgi_to_hash ( $in );
$id = $val->add_record ( $rec );

Right after the cgi_to_hash call, you have all the information in a hash reference $rec. So you could do:

$rec->{'TImage'} = &process_image($rec->{'URL'});

and when add_record is called, the record will be added.

Similiar deal for the admin in admin.cgi:

my $id = $db->add_record (&cgi_to_hash($in));

Hope that helps,

Alex

Quote Reply
Re: Altering fields when adding record In reply to
Great! That's what I needed to know!

Thanks!