Retunr primary key value after save

NickOg 06 Dec, 2011
Hi,

I need to retrieve the primary key of a record after it has been saved. I want to use that primary key as a receipt number. Is there some way to retrieve that from the db save function? I could do it by re-reading the database using something like date time saved and a unique key but it would be easier if one could get it back from the save action. I have a nasty feeling that can't happen!
GreyHead 06 Dec, 2011
Hi Nick,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

Both CFv3 & CFv4 make the saved data, including the primary key, available to you after the data is saved. There are many posts on this here as the work flow sequence means that it takes some gymnastics to use the data in an email in CF3.

That said I don't recommend using auto-incremented primary keys as identifiers as there is a potential security risk - if you hae 888 ans a key then you can reasonably deduce that 887 and 889 are also valid. I prefer to generate a unique random string after submission and before the DB Save and use that to identify the transaction.

Bob
NickOg 06 Dec, 2011
Hi Bob,

I am using 4.0 RC2.0 - I will go check that is the latest. As it happens, security for this project, isn't a concern but none-the-less I take your point and will work something else out. I suspect that the users are going to be looking for a sequential receipt number but I can deal with that.

Thanks for the tip. I will go and have another look for the discussion on data after save.

Nick
GreyHead 06 Dec, 2011
Hi Nick,

CFV4 RC2.0 is the latest version (afaik).

The form data is saved in $form->data[$model_id] after a DB Save action and by default $model_id will be 'chronoform_data' so check $form->data['chronoform_data']['cf_id']

Bob
NickOg 06 Dec, 2011
Thanks Bob - I will have a look - maybe I can generates some sort of pseudo sequential number - something like primaryKey_Rnd
NickOg 07 Dec, 2011
Hi Bob,

That has answered my questions. Works a a treat. The only thing that threw me for a little while was that, as I hadn't generated the target table using chronoforms, the primary key wasn't named cf_id.

so, just for information of any one else chasing this

$form->data['[your model id']['your table primary key name']


Thanks again
Oh, and the all problem seems to have disappeared as well!

Regards
Nick
This topic is locked and no more replies can be posted.