Insert cf_id into the response email

websavages1 25 Jul, 2007
Greetings,

I have created a form and the results are email to the relevant party. However I would like to add the value for cf_id in the email.

Any ideas?

Cheers ws
GreyHead 25 Jul, 2007
Hi websavages1,

I'm assuming that cf_id here is the ChronoForms form id? If that's right then you can include a hidden field in your form like this:
<input type='hidden' name='cf_id' value='<?php echo $rows[0]->id ?>' />
and that will give you the form id in the form variable 'cf_id' that you can include in your e-mail like any other variable.

Does this help?

Bob
websavages1 25 Jul, 2007
Unfortunately not.

Once the user has submitted the form I would like to include the newly created cf_id in the email which is sent.

Doing it via your method means I can only access the data which has already been created.

Cheers ws
GreyHead 25 Jul, 2007
Hi websavages,

Sorry, I misunderstood the id you were looking for. At present the database entry is created after the e-mail is sent so you don't know what the cf_id will be (it's autogenerated when the database entry is written).

I'd need to go and check my MySQL manual but I think that there is an SQL command that will generate the 'next ID'. Perhaps putting that in the 'OnSubmit code- before email' would do the trick.

Bob
websavages1 25 Jul, 2007
So instead of the auto-generate section creating the database entry, the 'OnSubmit - before email' section generates the database entry. That's a possibility, however, how do I (once I have got the newly created cf_id value) get the value for cf_id into the email?

Cheers ws
Max_admin 25 Jul, 2007
Hi Ws,

Lets try this trick, at the onsubmit AFTER email box plz write :


echo $html_message;


what do you get after submitting the form now ?<br><br>Post edited by: admin, at: 2007/07/25 15:46
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 25 Jul, 2007
Hi ws,

Try putting this code in the 'On Submit code - before sending email' field (remember to replace 'jos_chronoforms_nn' with the name of your particular form table):
<?
$cf_id = 0;
$tablename = "jos_chronoforms_nn";
$query = "SHOW TABLE STATUS LIKE '$tablename'";
$result = mysql_query($query) or die ( "Query failed: " . mysql_error() . "
" . $query );
$row = mysql_fetch_assoc($result);
$cf_id = $row['Auto_increment'];
?>
The you can use
<?php echo $cf_id ?>
in your email template.

Note that this bypasses the Joomla database handler and requires that you find the mysql tablename e.g. jos_chronoforms_nn' instead of the Joomla version '#__chronoforms_nn'.

Bob<br><br>Post edited by: GreyHead, at: 2007/07/26 10:04
websavages1 26 Jul, 2007
Oops can't delete a reply. I didn't read the reply on the second page. I'll give it a go today (overnight your time)

Cheers ws<br><br>Post edited by: websavages1, at: 2007/07/26 02:46
websavages1 26 Jul, 2007
No joy, the email source contains the php code un parsed.

Cheers ws
GreyHead 26 Jul, 2007
Hi ws,

I'm not sure if you're replying to my post or Max's. I'm hoping that it's Max's๐Ÿ˜‰ as mine *should* give you what you want.

Bob
websavages1 27 Jul, 2007
I tried both methods and agree that yours should give me what I need, however the email being received by the email client has the <?php echo $cf_id; ?> code (unparsed) in it.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>		
<base href="http://www.xxxxxxxxxxxxx.au/" />
<style type="text/css">
</style>			  
</head>
<body>
sfff has submitted the following High service request.<br />
sfff would like to instigate "fff" with the following scope:<br />
sddfs
<br />
<br />
and the reason for this is:<br />
fsdfsdsdfsd
<br />
<br />
This request was submitted on the 27th of July 2007 and has been 
assigned as Service Request Number (SRN): <?php echo $cf_id; ?>
</body>
</html>


With the following as my email template


{requestorName} has submitted the following {priority} service request.<br />
{requestorName} would like to instigate "{projectName}" with the following scope:<br />
{scope}
<br />
<br />
and the reason for this is:<br />
{benefit}
<br />
<br />
This request was submitted on the {date} and has been 
assigned as Service Request Number (SRN): <?php echo $cf_id; ?>


Post edited by: websavages1, at: 2007/07/27 01:43

Post edited by: websavages1, at: 2007/07/27 01:44<br><br>Post edited by: websavages1, at: 2007/07/27 01:44
Max_admin 27 Jul, 2007
Hi websavages1,

Thats fine yes because the email template will be parsed as a string only, so basically I see no way to obtain the cf_id value in the email with the current release of CF, we plan a very soon release and I will really try to include this feature in it, how much time you can wait ?

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 27 Jul, 2007
Hi ws & Max,

Sorry, I didn't do enough checking. This does work with a template but you need an extra line.
<?
$cf_id = 0;
$query = "SHOW TABLE STATUS LIKE 'jos_chronoforms_1'";
$result = mysql_query($query) or die ( "Query failed: " . mysql_error() . "
" . $query );
$row = mysql_fetch_assoc($result);
$cf_id = $row['Auto_increment'];
$html_message = str_replace( "#####", $cf_id, $html_message);
?>


If you put ##### in your template where you want the cf_id this will work. (I couldn't get it to work with '{cf_id}' as a marker though.)

Bob
websavages1 27 Jul, 2007
How long can it wait, about five minutes longer than it will take you to announce a new release.

If you could include it that would be fantastic.

Cheers ws

Edit: Damn that's the second time I have replied to a post before I read all the replies. I will try the latest suggestion as per Bob's post (Dated 2007/07/27 09:47) My original statement above regarding Max's reply will also be valid.

Thanks to both of you for such a great effort.

Cheers ws<br><br>Post edited by: websavages1, at: 2007/07/27 12:12
websavages1 03 Aug, 2007
I have just implemented what Bob suggested and it works a charm. Thank you both.

Cheers ws
jeffw 17 Mar, 2008
Hi, I'm hijacking this old thread because I want to do the same, but the solution
SHOW TABLE STATUS LIKE 'jos_chronoforms_1'
could go wrong if two forms are submitted at the same time.

A better solutions I think would be use
$return_id = $database->insertid();
in the auto generated form.

It works so far as I get the correct value in the Auto Generated Code, but how can I pass it to the On Submit Code? I tried it but the variable keeps coming up empty.

Btw, this is my first post and thanks for ChronoEngine. It works great!
GreyHead 17 Mar, 2008
Hi jeffw,

I think that variables declared in the various ChronoForms boxes only have local scope. So the easy, if slightly cumbrous, way round this is to put a hidden input into your form and then set the corresponding entry in the $_POST (or $_REQUEST) array to the new value. These have global scope and you can pick them up again in the OnSubmit box.

Bob
Max_admin 18 Mar, 2008
Hi jeffw,

The autogenerated code is executed the last thing too so I don't think you can get the value at the onsubmit code!๐Ÿ˜Ÿ

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jeffw 18 Mar, 2008
Hi Bob, Max,

I realized after I could pass a value from the On Submit code to the autogenerated code, that autogenerate was run last.

So instead I turned off emails in the plugin and send them after the autogenerate code, so I can use the id.

Thanks both for your help!
OCS 25 Mar, 2008

So instead I turned off emails in the plugin and send them after the autogenerate code, so I can use the id.


Hi, i'm struggling with the same problem. Can you give example code how did you do it and where to place the code?

Thanks if you can help.
jeffw 25 Mar, 2008
This worked for me, but it does require making changes to chronocontact.php and I'll repeat what the Autogenerated tab says: "Please don't touch this unless you know what you are doing". Also remember to make a backup of your form and chronocontact.php before making any changes.

What I did was switch the Onsubmit after sending email code to run after the Autogenerate code.

Replace (starting on line 493)
/**
 * Run the On-submit 'post e-mail' code if there is any
 */
if ( !empty($rows[0]->onsubmitcode) ) {
eval( "?>".$rows[0]->onsubmitcode );
}

/**
 * Run the SQL query if there is one
 */
if ( !empty($rows[0]->autogenerated) ) {
eval( "?>".$rows[0]->autogenerated );
}
With
/**
 * Run the SQL query if there is one
 */
if ( !empty($rows[0]->autogenerated) ) {
eval( "?>".$rows[0]->autogenerated );
}
/**
 * Run the On-submit 'post e-mail' code if there is any
 */
if ( !empty($rows[0]->onsubmitcode) ) {
eval( "?>".$rows[0]->onsubmitcode );
}
Then you can query the cf_id in the Autogenerated code with
$return_id = $database->insertid();

so it will be available in the Onsubmit code.
OCS 27 Mar, 2008

Then you can query the cf_id in the Autogenerated code with

$return_id = $database->insertid();

so it will be available in the Onsubmit code.


Thank you. This helped me a lot!
GreyHead 27 Mar, 2008
Hi jeffw & OCS,

You can get the same result without hacking the core code if you add your 'OnSubmit after' code at the bottom of the Autogenerated Code box (after the existing AutoGenerated code). Not perfect but easier than remembering to re-hack the core if you upgrade.

Bob
OCS 27 Mar, 2008

You can get the same result without hacking the core code if you add your 'OnSubmit after' code at the bottom of the Autogenerated Code box (after the existing AutoGenerated code). Not perfect but easier than remembering to re-hack the core if you upgrade.


Yeah, that crossed my mind when I did the changes. The I felt that it would be logical to do that "OnSubmit after" code, because I made a custom auto-email-repy script there.

I'm keeping the steps (before submit, submit and after submit) separate. That's the best way for me to understand how the form works๐Ÿ™‚
jeffw 28 Mar, 2008

Hi jeffw & OCS,

You can get the same result without hacking the core code if you add your 'OnSubmit after' code at the bottom of the Autogenerated Code box (after the existing AutoGenerated code). Not perfect but easier than remembering to re-hack the core if you upgrade.

Bob


Hi Bob,

That's true for any custom code you add to Onsubmit after, but I want the emails to be sent after the Autogenerate code (after the record is saved) and that is always called from Onsubmit.
GreyHead 28 Mar, 2008
Hi jeffw,

No, I don't think so. Anything you add to the Autogenerated code tab **after** the code that CF generates will be executed after the record is saved.

Bob
Atoyo 15 Apr, 2010
I'm using Joomla ver 1.5.15, I installed Chronoforms, I prepared 4 e-mail templates with {name}, {ipaddress},... and all is send successfully; now I tried to insert the cf_id into e-mail like suggested in these posts, but nothing.
I inserted the "#####" string in e-mail templates and i added this code:
<? 
$cf_id = 0;
$query = "SHOW TABLE STATUS LIKE 'sdc_chronoforms_frm_richiesta'";//sdc_chronoforms_frm_richiesta is my copiled form table;
$result = mysql_query($query) or die ( "Query failed: " . mysql_error() . "
" . $query );
$row = mysql_fetch_assoc($result);
$cf_id = $row['Auto_increment'];
$html_message = str_replace( "#####", "cf_id", $html_message);
?>

in On Submit code - before sending email of Form Code, but ##### don't change.
I don't understand why the command
$html_message = str_replace( "#####", "cf_id", $html_message);

does not work.

Bye bye Antonio
Atoyo 15 Apr, 2010
Sorry in my last reply into inserted code was $cf_id and not cf_id;

<? 
$cf_id = 0;
$query = "SHOW TABLE STATUS LIKE 'sdc_chronoforms_frm_richiesta'";
$result = mysql_query($query) or die ( "Query failed: " . mysql_error() . "
" . $query );
$row = mysql_fetch_assoc($result);
$cf_id = $row['Auto_increment'];
$html_message = str_replace( "#####", "$cf_id", $html_message);
?>


This code don't work

Bye Antonio
GreyHead 15 Apr, 2010
Hi Antonio,

This is all very old code from previous versions of ChronoForms. There are several newer threads explaining how to do this with the current release.

Bob
diego.matos 19 May, 2011
Hi,

I'm with the some problem, I can't to show cf_id in my email.
when I try to insert code php in my email template, my code php is commented.

Anybody help me!

My Joomla is 1.5.23
My Chronoform is 3.2.0
GreyHead 20 May, 2011
Hi diegos.matos,

Please see my post to Antonio - the last post before yours.

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

VPS & Email Hosting 20% discount
hostinger