Forums

Get ID of record on Submission of Form

keith.wadson448 21d ago

So, I have a function that I brought over from BreezingForms when I switched over to ChronoForms8. It is a block of PHP which sends out a curl call to a geolocator service and creates map markers based on the addresses submitted in the form. I got everything to work correctly here, with one exception:

To label the new markers with a link back to the submitted record, I need to have the ID of the record on submission to be passed to the new markers. I tried using $this->data("id") to grab the ID in the PHP block on the Submit tab, but this seems to pull a NULL value. Looking at the debug, I think the submission ID is created after the code in the Submit tab executes. 

So, I want to ask if I am understanding the order of code correctly here and if there is any way to get the pending ID during submission. If not, I will just add a database call to get the final record ID from the database and increment the number. I don't want to add this extra call if I don't have to, so if anyone knows a simple solution, that would help me greatly.

Thank you for your time!

Max_admin 21d ago
Answer

if you need the ID of the "Log" record then this is added the last thing at the last page submit, so you would not be able to use it before that (in the submit)

So you will need a Save Data action to save to your table, in that save data action you need to set the table's Primary key in the behavior, and after the action you can get the new id value using {var:save_data_name.id} where "save_data_name" is the name of the Save Data and "id" is the name of the auto increment primary key

Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
keith.wadson448 21d ago

Ok, thank you for the suggestion.

Since it is in the php block, I can't use the shortcode to access the variable. Instead, does ($this->data("save_data56","id")) look like the proper call to get the id from a Save Data block of that name? Using it returns an error on submission:

Field 'form_id' doesn't have a default value

So, I must still be doing something wrong. The save data block looks like this, placed before my php block that requires the id: 

Max_admin 20d ago

use the following PHP code to get the variable after the Save Data action:

$this->get("save_data56.id")

Let me know how this works for you

Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
keith.wadson448 15d ago
1 Likes

Just getting back to this problem today. 

That was the correct call to recover the id from the save data, but it still wouldn't process the database call and came back with a NULL array under savedata56 in the debug.

With a little more experimenting, I found that manually setting a value to the form_id in savedata56 via Modify Data Source allowed it to create the table entry properly!

With this last change everything is working properly now, so this is solved!

Thank you for all the time and help.

Max_admin 13d ago

Hi Keith

Good solution, but if you do this then you will have 2 log entries per form submission, the one you store with Save Data and another one stored at the end of the form, unless you disable the Log setting in your form

and you had to set the form_id field value because that column does not have a default value set, so you have to do this manually, your form id should be set correctly though in order to have the log entry stored under your form's records

Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
You need to login to be able to post a reply.