Reputation: 141
i have very, very simple logic hook- I am still learning and I am confused at the start. I turn on Developer mode.
I already have field "FIRST_NAME" in Contacts module. I Created my field "MY_FIELD" also in COntacts module.
In logic_hooks.php file I added
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'Value from one field to another', 'custom/modules/Contacts/my.php', 'User_hook','copy');
In my.php file I added
class User_hook {
function copy(&$bean, $event, $arguments)
{
$bean->my_field_c = $bean->fetched_row['first_name']. " - additional text";
}
}
So when I entered in First_Name value "First" I am getting in My field value "-additional text" but I should get "First- additional text." If I go to Edit View and enter in First name field "Second" I am getting in My field value "First - additional text" but I should get "Second - additional text". If I enetein Edit View "Third" I am getting in My field "Third - addiitional text" but I should get "Third - additional text".
So obviously my logic hook is executed with delay in one iteration- why and how to change it? This is my first hook so I am not so experience. Thanks for help
Upvotes: 0
Views: 2726
Reputation: 152
$bean->fetched_row['first_name'] will return the value of the field BEFORE you change it. You'd use this to see what the value of first_name was before the user changed it on the form.
Try using
class User_hook {
function copy(&$bean, $event, $arguments)
{
$bean->my_field_c = $bean->first_name. " - additional text";
}
}
Upvotes: 5