operational hook issue

juergen_mueller

DaDaBIK Guru
Hi Eugenio

I still an issue when trying to send en email via operational hook, like:

$hooks['my_users']['update']['before'] = 'dadabik_send_notice_before_ddbk_users_update';

function ddadabik_send_notice_before_ddbk_users_update($id_user)
{
global $conn;

// get the username from the ID
$sql = "SELECT username_user FROM my_users WHERE id_user = :id_user";

$res_prepare = prepare_db($conn, $sql);

$res_bind = bind_param_db($res_prepare, ':id_user', $id_user);

$res = execute_prepared_db($res_prepare,0);

$row = fetch_row_db($res_prepare);

mail ('your@mail.com', 'User account updated', 'User account ('.$row['username_user'].') has been updated.');

}

I am getting an email but the mail body remains empty, meaning that I don't know which record had been updated. What am I doing wrong?

Best

Juergen
 

eugenio

Administrator
Staff member
Hello Juergen,
I think the problem is just the use of a before insert hook, if you need the id of the user just inserted, you should use the after insert hook.
Let me know if it works.

Best,
 

juergen_mueller

DaDaBIK Guru
Hi, Eugenio

Thanks for your reply. I changed it to 'after', but it's still the same problem: I'm getting a mail without body...

Best

Juergen
 

eugenio

Administrator
Staff member
Very strange ... when you say "without body" you mean literally without body or you get something like:

User account ( ) has been updated.

?

Best,
 

juergen_mueller

DaDaBIK Guru
Hi Eugenio

Sorry, I was not precise enough.

I get some information in the body (see screenshot) but nothing about the record.

Cheers

Juergen
view
 

eugenio

Administrator
Staff member
Hello,
looking at the screenshot, it seems you are receiving a different email body respect to the one you are building in your code.
Are you sure that the email you receive is from the code and not from the built-in DaDaBK email notification feature?

Best,
 

juergen_mueller

DaDaBIK Guru
Hi, Eugenio

Thanks for the hint. I unchecked the option in the main config file - I did remember having activated this feature (during main installation).

However, I notice the following:

- the above example is for a view, this does not seem to work; I don't get mail at all
- I installed another example for a table. In this case I get the mail including the body. However, the ('.$row['FIELD'].') still remains empty...

Best,

Juergen
 
I'm not sure if this is relevant, but the function name is spelled differently in your example code, starting with DDada:
$hooks['my_users']['update']['before'] = 'dadabik_send_notice_before_ddbk_users_update';

function ddadabik_send_notice_before_ddbk_users_update($id_user)
 

juergen_mueller

DaDaBIK Guru
Hi LurkingKiwi

Arrgh, so embarrassing, this was it. Too much coding these days. I did not double check because the mail arrived.

Thanks for the hint,

Juergen
 
Top