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

Preserving field through modify?

Quote Reply
Preserving field through modify?
I've added another field to my link and validate tables called 'Package'. Works great, accept when a user modifys their information, it defaults back to the field default instead of carrying the old link info through and re-posting it back to the validate table.

Can someone show me how (without passing hidden fields in templates), when the script pulls the links existing info out of the database in its final call, it also includes that links existing 'Package' value when it posts it back to the validate table. I've tried adding a line (at the bottom) to this section below but I can't get it to work...

# Search for the link.
$db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";
$links = $db->query ( { URL => $in->param('Current URL'), ww => 1 } );
($db->hits > 0) or &site_html_modify_failure ({ Category => $category, error => "The link was not found in the database", %in }, $dynamic ) and return;

# Convert to hash.
$links = $db->array_to_hash ( ${$links}[0] );
foreach $key (keys %{$links}) {
$original->{$key} = $links->{$key};
exists $LINKS{add_system_fields}->{$key} and next;
$links->{$key} = $in->param($key);
}
$links->{'Add_Date'} = $original->{'Add_Date'};
$links->{'Mod_Date'} = $db->get_date;
$links->{'LinkID'} = $original->{'ID'};
$links->{'Mode'} = 'Modify';


## MY ATTEMPT HERE FOR PACKAGE PRESERVATION THROUGH MODIFY
$links->{'Package'} = $original->{'Package'};


...Then the rest of the modify script untouched.

Thanks in advance.

Regan.

Quote Reply
Re: Preserving field through modify? In reply to
Oops...sorry misread your comments..although they seemed a bit contradictory from the title of the Thread....

I will look at this more closely later.

Regards,

Eliot Lee



Quote Reply
Re: Preserving field through modify? In reply to
I've never had a problem with this. I've added dozens of fields, where the data is carried through updates, and everything.

Somewhere, you must be re-setting the values.

Whatever is in the fields in the Validate database (when you view the records) will be added to the database.

Are you overwriting the field with a field in the modify.html template??

If your modify template is the same as your add template, maybe you are.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Preserving field through modify? In reply to
The field 'Package' is only available in the admin area, so the user never gets to set it in the add or modify pages. When they add their link the first time, it's set to a default of 1 in the validate table. The Admin can then set it to 1 of 4 values.

The problem is, when the user then modifies their links information again, that value (which the admin might have set to 3) is defaulting back to 1 again when it goes into the validate table. I thought that part of the modify routine could also grab the existing 'Package' value and just pass it back thorough to the validate table again?

I haven't got it passing a Package value through the modify templates so it can't be getting overridden anywhere at the moment. Hopefully there's a way to do it without the hidden fields?

Hope that makes sense.
Thanks.

Quote Reply
Re: Preserving field through modify? In reply to
I see the problem. By not passing the value in, you are triggering the default value for that field, which causes it to override the existing value.

Code:
$rec->{Mode} = 'Modify';

# Add the link to the validation database.
$val->add_record ( $rec ) or &site_html_modify_failure ( { error => $Links::DBSQL::error,
Category => $category, %in, %$USER }, $dynamic) and return;
Right above that, where you make the assignments, you want to carry the original back to the insert into the Validate.

$rec->{Package} = original{Package};



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Preserving field through modify? In reply to
Thank you pugdog!

I had it written the right way but in the wrong place by a few lines - it's working great!

Thanks for that!

Regan.