doesn't work. One workaround I have found is:setQuery($sql);$result = $db->loadObject();$_POST['new_id'] = $result->id;?>and then of course referencing {new_id} in the email template. This hack works as long as the insert is successful, but pretty weak IMHO. The fact that this works suggests that this code in the "On Submit before sending email" section is executed before the email is sent, AND before the data is saved. Is there any hook that's between saving and sending?Is there any other more reliable way to send the insert_id ( insertid() ) of the submitted data's row in the email?I have looked through the forums for a couple hours, but if I overlooked something, a link would be greatly appreciated.🙂"> How to include Insert_id in email - Forums

Forums

How to include Insert_id in email

itsfridaymoanin 08 Jul, 2010
I'd like to include the cf_id of the form submission just inserted into the database. I've learned that you can create new variables accessible in email templates {new_var} by assigning them to $_POST[new_var] in the "On Submit code - before sending email:" section (with the exception of $_POST['cf_id'] - that disables the data from being saved!).

But
<?php $db =& JFactory::getDBO(); $_POST['new_id'] = $db->insertid(); ?>
doesn't work.

One workaround I have found is:
<?php
$sql = "SELECT MAX(cf_id) + 1 AS id FROM jos_chronoforms_mytable";
$db->setQuery($sql);
$result = $db->loadObject();
$_POST['new_id'] = $result->id;
?>


and then of course referencing {new_id} in the email template.

This hack works as long as the insert is successful, but pretty weak IMHO. The fact that this works suggests that this code in the "On Submit before sending email" section is executed before the email is sent, AND before the data is saved. Is there any hook that's between saving and sending?

Is there any other more reliable way to send the insert_id ( insertid() ) of the submitted data's row in the email?

I have looked through the forums for a couple hours, but if I overlooked something, a link would be greatly appreciated.🙂
GreyHead 08 Jul, 2010
Hi itsfridaymoanin,

This is here many times.

You need to change the DB Connection settings to make sure that the Database save is 'Before Email.

Then include this code in the Email Template (turn off the Rich template editor in the Email Setup to let you add PHP). You need toreplace my_form_name with the name of your form
<?php
$MyForm =& CFChronoForm::getInstance();
$cf_id = $MyForm->tablerow['jos_chronoforms_my_form_name']->cf_id;
?>

Then use <?php echo $cf_id; ?> where you want the cf_id included.

Bob

PS Using the cf-id as a public link is not always the best approach. There may be a security risk because it is easy to guess other cf_id as they are always in sequence. If this is a problem then use a random identifier string instead.
This topic is locked and no more replies can be posted.