There are several ways of identifying submitted records and which you use depends on your form.
Database Record ID
If you are saving records to a database table and just want to be able to look them up later then you can use the table ID column. This is an auto-incremented integer e.g. 101, 102, 103, . . . that is created when the record is saved.
You can reference this number after the DB Save action in the form data array. If you created your table with ChronoForms then this will probably be
$form->data['chronoform_data']['cf_id']
If you used a specific model id and/or your table has a different primary key column the values will be:
$form->data['model_id']['column_name']
There are two possible problems with using the primary key as an identifier:
- It is only available after the record is saved
- There is a possible security risk if you use this number in any public way, for eaxmple in a URL, then it is easy to guess that if id=101 is valid then id=102 and id=103 are probably valid as well.
The cf_id can be useful to identify the current record if you are working with multi-page forms. If you use the code below in a Custom Code action to add the cf_id to the current form data and add a hidden input to your form with the name cf_id then you can carry the id forward so that data input on later pages will update the same record.
<?php $form->data['cf_id'] = $form->data['chronoform_data']['cf_id']; ?>
Database UID
If you created your database table with ChronoForms then there will be a cf_uid column included which the DB Save action will fill with a 32 character random string like this 679c1910bf4e875d3c05ffbbc0e968f2. This whole string is random and though it is not actually checked for uniqueness the likelihood of it being repeated is very very small.
You can access this after the DB Save action in a similar way to the cf_id above.
This identifier does not have the same security problems and is computer friendly but not human friendly. You should not use it if a user will ever need to read and/or type it.
Unique ID [GH]
If you need a human friendly ID, or an ID that is available before the DB Save action runs then look at my custom Unique ID [GH] action (I also have a beta version for CFv5, please PM me to get a copy). This will generate a random string using a template that you can set e.g. the template AA999X might generate the id TY564X and will check against at database table that the string has not already been used.
You can use this ID in any email, thank you message or URL - including, for example, to identify a transaction to a payment gateway like PayPal. You do need to ensure that the ID is saved to the datbase table by a DB Save action.

Comments: