Dynamic Submission ID

d3vilr3d 17 Jun, 2008
Hi all,

I'm trying to attach an ID to each form submission. The ID needs to be formated like mmddyy-### (example: 061708-001). Any suggestion on how this can be achieved?

I think php echo from the db assigns to a hidden field that's date formatted could do the trick...

Thanks,
William
GreyHead 17 Jun, 2008
Hi William,

If it needs to be a serial field than you are going to need some way to store the value. You could to this in a database table or a text file . . .

You probably don't want it in the form because not all forms will be submitted. All you need in the form is a hidden field as a place holder:
<input type='hidden' name='id' value='' />
You can generate the id in the OnSubmit before box. and include it in both the email and the data saved to the database.
<?php
$serial = //find last value
$_POST['id'] = date('dmy').$serial++;
// save $serial
?>
Bob
d3vilr3d 17 Jun, 2008
i will try that.

thanks bob
d3vilr3d 17 Jun, 2008
Hi Bob,

I tried inserting your code, but i'm quite lost on
$serial =


What should that equal to?

My debug shows
[id] => 
GreyHead 18 Jun, 2008
Hi William,

Yup, you need to write some code to create/look-up your serial number.

Bob
dwayne 26 Jun, 2008
Here's what I did for the code for the serial number: (added to On Submit code - before sending email)
<?php
$myFile = "requestnum.txt";
$handle = fopen($myFile, 'r');
$serial = fread($handle, 3);
fclose($handle);

$serial++;
$_POST['requestid'] = date('dmy').$serial;  

$data = sprintf("%'03u", $serial) . "\n";
echo $data;
$Handle = fopen($myFile, 'w');
fwrite($Handle, $data);
fclose($Handle);
?>
Now in my email template I have:
|{requestid}|{email}|{institution_name}|{institution_address}|
but when I receive the email the requestid is blank, why is that, what am I doing wrong?
GreyHead 27 Jun, 2008
Hi dwayne,

Add a hidden field to your form html so that ChronoForms knows to look for a requestid variable:
<input type="hidden" name="requestid" value="" />
Bob
dwayne 27 Jun, 2008
I did add the hidden variable to the form and it comes up blank in the email. Any other ideas?
GreyHead 27 Jun, 2008
Hi Dwayne,

Please take a form backup in the Forms Manager and post it here or email to the address in my sig so I can take a closer look.

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