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
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
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
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
Cheers 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
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
Cheers ws<br><br>Post edited by: websavages1, at: 2007/07/26 02:46
Cheers 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
<!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
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
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
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
Cheers ws
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!
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
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
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!
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.
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.
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!
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
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๐
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.
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
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
<?
$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
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
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