Forums

Save uniq_id value

dnigra 15 Mar, 2016
I want to save the uniq_id created when saving form data to the DB and reuse it as a unique identifier in a payment site. I can reuse the primary key, (id) but can't seem to get a hold on the uniq-id.

After the DB save, I have this custom code:

$form->data['merchant_ref_no'] = $form->data['id'];

$form->data['u_id']=$form->data['uniq_id'];


The debugger gives this for the Data Array:

Array
(
    [option] => com_chronoforms5
    [chronoform] => MyForm
.
.
.
   [merchant_ref_no] => 14
    [id] => 14
    [name] => Joe User
    [u_id] => 
)


and for the Debug Info:

Array
(
    [9] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `*******************` (`first_name`, `last_name`, `institution`, `email`, `phone`, `present`, `talk_title`, `diet`, `merchant_ref_no`, `id`, `uniq_id`, `created`) values ('Joe', 'User', 'Joe Inc.', 'joe@joeuser.com', '111111111', 'Yes', 'My talk title', 'I am a vegetarian', '', '', '8afeaaeae771e76d8a69606a8c63ea8cdd20e69f', '2016-03-15 17:42:50');
                        )

                )

        )

)


How can I save & reuse the uniq_id field? Thank you for any suggestions.
GreyHead 15 Mar, 2016
Hi dnigra,

What uniq_id is this? Is it the one that ChronoForms creates in the DB Save? Is your Debugger after the DB Save action? If ChronoForms saves it to the $form->data array you should see it there. If not you could read it from saved record or - IHBO better - ask me for my Unique ID [GH] action that lets you create a short unique ID before the DB Save.

Bob
dnigra 15 Mar, 2016
Yes, this is the uniq_id that Chronoforms creates in the DB Save. Yes, order of actions is: DB Save, custom code, debugger. That's why I am puzzled that I cannot see the uniq_id. It does not show up in the form->data array although id does.

But in any case, I will bite on the Unique ID action. Where can I get it?
dnigra 17 Mar, 2016
Hello again,

Thank you very much for the unique id action. I get a nice random unique id in the DB. But I am running in to another problem.

The only way I can pass that unique id on is if it is included in the redirect url. It's set up this way:
[list]user submits form
[list]Unique ID action
DB save action
[/list]
form redirects to confirmation page/ proceed to payment site form
payment site form submits to payment site[/list]

The generated unique id is saved in the DB in the correct column. However, it does not appear in the form->data array in the confirmation form UNLESS it is included as an extra param in the redirect action. In which case, it shows up in the URL, of course.

NoExtraParam below is a screenshot of what happens when merchant_ref_no is NOT listed as an extra param in the redirct action

MRN_ExtraParam is a screenshot of what happens when merchant_ref_no is listed as an extra param inthe redirect action.


I think I am missing something very basic here and I apologize for that. Can you point me in the right direction?

Many thanks, dnigra
dnigra 17 Mar, 2016
You know what? Never mind, I'm looking in the wrong place. 😶

I'm not sure I have solved it, but I know that long rambling previous message is looking in the wrong place.

I'll get back to you...................
GreyHead 17 Mar, 2016
Hi dnigra,

Does it help if you set the Unique ID name as merchant_ref_no ?

Bob
dnigra 17 Mar, 2016
It is. 😟
GreyHead 17 Mar, 2016
Hi dnigra,

Sorry, in that case I'm lost :-( What exactly is the problem here?

Bob
dnigra 17 Mar, 2016
I have to use an external storefront to process payment for a workshop registration. I have to POST the data to this form.

Form A gathers registration info.
Form P is the payment form.

I believe:
- if in Form A, I set the Action URL to be Form P, I can't do the Create unique Id action, server side verification or DB save.
- if in Form A, I instead use a redirect action after all the usual above(verify, db write, etc) it's not a POST and form P won't accept it.

SO that led me to set up Form B.

Form A gathers info, creates a unique id, writes a record into the DB, then redirects to Form B.

If I set Form A to just dump the POST array and turn on the debug action, I see all the fields I need, including 'merchant_ref_no", which is the unique id created by the Unique Id action.

See FormA_debugOnly below.

Now, I set FormA to redirect to Form B. On submission, Form B only echoes back the POST array and the debug info. But merchant_ref_no is blank.

See FormB_PostandDebug below.

Form B has a hidden merchant_ref_no field which has no value set.

I tried this custom code in the Load action for Form B, before the render form action:
<?php


$form->data['merchant_ref_no'] = $_POST['merchant_ref_no'];
?>

but that didn't work either.

Is that clearer, and what am I doing wrong?
GreyHead 18 Mar, 2016
Hi dnigra,

You can use the Data to Session and Session to Data actions to pass data between forms; or you could make this one multi-page form.

Do you need to send the User to the shop front along with the data?

If so then I would add a Confirmation page to form P, put all the data in there as hidden inputs, then add a Submit button labelled 'Pay Now' and have that form submit to the gateway. That will send the data via POST and the User to the shop front.

In not, then you can use the cURL action to send just the data via POST.

Bob
dnigra 18 Mar, 2016
Hi Bob,

I guess I wasn't clear. Form P is the payment site and I dont have control over that form, I just need to pass data and the user to it.

Do you need to send the User to the shop front along with the data?

If so then I would add a Confirmation page to form P, put all the data in there as hidden inputs, then add a Submit button labelled 'Pay Now' and have that form submit to the gateway. That will send the data via POST and the User to the shop front.



So this is what I am trying to do. Form B is my confirmation page.. I could make it the 2nd page of Form A instead of a separate form.
dnigra 18 Mar, 2016
Bob,

I ended up making a (new) 2 page form as you suggested. The first page gathers info from teh user, the second page displays a "you are now going to the payment site" message. Everything worked like a charm.. once I remembered to turn on the Unique Id action. 🙄

Thanks again for your help.
This topic is locked and no more replies can be posted.