Forums

Unique Incremental Number

K2Joom 01 Apr, 2014
I am producing a form to submit calibration data and as such, each submission needs to have a unique, incremental, not random number.

The whole form is designed and I finally got my head around the PDF design, so now the Save+ Download PDF works too.
What I have done is use the {cf_id} tag for the certificate number. In theory this should work, however the PDF seems to be created before the form is submitted and the PDF just shows the tag and not what has been put in the table.
In my parameters, the HTML to PDF is after the DB Save, so I expected the form data to be saved to db and load the cf_id, however in hindsight I guess the required calibration number should be added to the HTML onload?

Think I have gotten myself confused and not sure what the best way to proceed is.
If I need my cert numbers to start at 3000, should I query an existing field first to get the next number, onpage load so that it is available when onsubmit and html to pdf takes place.

OK, I am rambling now . . . . .๐Ÿ™‚
GreyHead 01 Apr, 2014
Hi K2Joom,

You've go the right approach in the way you have it set up now. You don't need to do anything extra in the On Load event. The PDF *can't* be created before the form is submitted; nor can the data be saved and the record id created. I suggest that you add a Debugger action (or two) to the On Submit event so that you can see what data is available where.

You may need to add a Custom Code action to modify the cf_id if you need the serial numbers to start from 3000 (or you need to change the index start number for the table using PHPMyAdmin.

Bob
K2Joom 01 Apr, 2014
Hi Bob,

Thanks for the reassurance in my understanding of what is happening.

So as the cf_id is not created until the submit is done and the pdf cant process the cf_id is not loaded in the form, I was thinking about adding a hidden field for this number, called cc_number. This has already been created in the db.
The thinking is when the form loads, query the cc_number in the DB and add 1 to the count (I can drop a dummy record in to start at 3000). This way, the form loads, 3001 is then loaded to the hidden cc_number field.
The PDF would be coded to display the tag {cc_number}.
Form submits, save data to db, pdf is created from form data, including hidden field.

Does that sound logical, doable ?

Changing the cf_id on PHPMyAdmin could be viable too.

I shall take a look at debugger too.

Thanks Bob.
GreyHead 02 Apr, 2014
Hi K2Joom,

Sorry, I don't understand what you are saying. The PDF is created **after** the form is submitted and you should have it after the DB Save action. That makes the cf_id available to you to add into the PDF.

Bob
K2Joom 02 Apr, 2014
Hi Bob,

OK, confused now, sorry I thought I understood this aspect๐Ÿ™‚

I have entered {cf_id} in the Content of the HTML to PDF event which is trigged On Submit, after On Save.
When the form is saved, the PDF is created and downloads, but it displays {cf_id} as text and not the actual ID saved in the DB.

My understanding was that all other fields have data entered in them, when the form is submitted all fields are saved to the DB and the HTML is passed to PDF. Although the {cf_id} is used in the PDF code, will it go and fetch that data from the db after saving?

How should that be setup?

I was expecting that an onload function would be required to fetch the next cf_id from the table, so it was ready to be saved and passed to PDF.
GreyHead 02 Apr, 2014
Hi K2Joom,

Please see this FAQ which has the info on getting the record id you need.

Bob
K2Joom 02 Apr, 2014
Hi Bob,

Yep, I have that on bookmark๐Ÿ™‚
But not exactly sure where
$form->data['chronoform_data']['cf_id']
should be placed, if at all, is that created automatically if using the wizard?

I added custom php code per the example
<?php
$form->data['cf_id'] = $form->data['chronoform_data']['cf_id'];
?>
to a custom code action to load the current cf_id to the form, then created a hidden field for cf_id and have {cf_id} in the pdf, but still wont display it hahaha.

Simon
GreyHead 03 Apr, 2014
Hi Simon,

The $form->data['chronoform_data']['cf_id'] is created automatically by the DB Save action. If you add {chronoform_data.cf_id} into the PDF that should show the value.

If you need to manipulate the cf_id to give you the format of ID you need then you can use a Custom Code action.

You do **not** need hidden inputs or anything else in the On Load action - this is all done On Submit !!!

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