Postprocess saved data

How to retrieve the auto-increment ID after saving form data in ChronoForms.

Overview

The issue occurs because the correct variable path to access the newly inserted record's ID (aid) is not being used in the PHP code.
Use the correct variable path `save_data3.aid` with the `$this->get()` method to successfully retrieve the ID for post-processing.

Answered
ChronoForms v6
Ax Axel Richter 08 May, 2019
Hi all,

I have a form including a "Save data" and insert a record. Afterwards I would like to postprocess the data using JDatabase. The problem is to get the "aid" of the newly inserted record. The debugger shows:
Array
(
    [submit_validate_fields] => Array
        (
            [log] => Automatic validation enabled.
            [var] => 1
        )

    [save_data3] => Array
        (
            [data] => Array
                (
                    [created] => 2019-05-08 06:26:57
                    [user_id] => 54
                    [company] => Katholische Panzerwaschanstalt GmbH
                    [address] => Musterstrasse 4
                    [country] => DEU
                    [product] => tce
                    [expiration] => 2019-05-31 08:26:00
                    [state] => 0
                    [operating_system] => ["unx"]
                    [databases_mainframe] => ["db2"]
                    [databases_server] => ["my"]
                    [next_message] => My message
                )

            [_success] => Data saved successfully
            [log] => Array
                (
                    [0] => INSERT INTO `jos_chronoforms_data_reservierungseintrag` (`created`, `user_id`, `company`, `address`, `country`, `product`, `expiration`, `state`, `operating_system`, `databases_mainframe`, `databases_server`, `next_message`)  values  ('2019-05-08 06:26:57', '54', 'Katholische Panzerwaschanstalt GmbH', 'Musterstrasse 4', 'DEU', 'tce', '2019-05-31 08:26:00', '0', '["unx"]', '["db2"]', '["my"]', 'My message');
                )

            [var] => Array
                (
                    [created] => 2019-05-08 06:26:57
                    [user_id] => 54
                    [company] => Katholische Panzerwaschanstalt GmbH
                    [address] => Musterstrasse 4
                    [country] => DEU
                    [product] => tce
                    [expiration] => 2019-05-31 08:26:00
                    [state] => 0
                    [operating_system] => ["unx"]
                    [databases_mainframe] => ["db2"]
                    [databases_server] => ["my"]
                    [next_message] => My message
                    [aid] => 33
                )

        )

)
…and I'm inretested in the aid (shown in bold). For the update I use a </PHP> tag and tried:
$var = $this->get('{var:save_data3.var.aid}', "-1");
$var = $this->get('{var:save_data3[aid]}', "-1");
$var = $this->get('{var:save_data3.data.aid}', "-1");
$var = $this->get('{var:save_data3.data[aid]}', "-1");
…and I tried the same with…
$var = $this->data('{var:save_data3.var.aid}', "-1");
$var = $this->data('{var:save_data3[aid]}', "-1");
$var = $this->data('{var:save_data3.data.aid}', "-1");
$var = $this->data('{var:save_data3.data[aid]}', "-1");
…and in each case I received -1.

Any clue?

Thank you in advance,
Axel.
he healyhatman 08 May, 2019
Answer
$this->get("save_data3.aid")


$this->data for URL parameters and form data
This topic is locked and no more replies can be posted.