Insert CustomModule info with Lead or Contact lookup

Insert CustomModule info with Lead or Contact lookup

Hi!

I was wondering how can i insert a record into a custom module and relate it lo a Lead or a Contact using a UNIQUE key, such as an email or the Lead / Contact ID? I am using PHP, so far I've tried with:

<FL val="SEID">Lead ID</FL> 
<FL val="SEMODULE">Leads</FL>

-------------------------------------------------

<FL val="Lead">Lead ID</FL>

-------------------------------------------------

<FL val="entityId">Lead ID</FL>


-------------------------------------------------

<FL val="WHOID">Lead ID</FL>


Also, all the above using Lead's email


With no luck, the record gets inserted but does not relate to any Lead, even tho the Lead Exists.

The only way i got it working was passing the name of the lead like this: 


<FL val="Lead">Lead Full Name</FL>

But this is VERY problematic, because if I have more than 1 lead with the same name, the relations gets all messed up.

Can anyone help me please? Im getting very frustrated, talked on the live chat about 4 times and no one knows how to help me...


Thanks!