Forums

How to transfer data from Submit-before to email field? [OK]

jmhook 20 Nov, 2008
I need to set field data in Submit-before and the data should be included in the mail sent. The field data should not be visible in the email form. I have tried the following, but the fields in the email are empty.

This should be very basic, but i just cant make it work. Other postings indicate that this is the method.

This is what i have tried:

Form html (part of):

 <input type="hidden" name="dateandtime" value="" />


Submit-before code (part of):

<?php
   JRequest::setVar('dateandtime',date('r'));
?>


Email template (part of):

Date and time (CET): {dateandtime} 


The email is set to plain text in the email settings.

The email contains the text "Date and time (CET): " But the field is empty!

Michael
GreyHead 20 Nov, 2008
Hi Michael,

It's one of the little quirks of ChronoForms that the OnSubmit before code is evaluated after the Email html - so this techniques doesn't work - though it's fine for data being saved in the database!

You can force a substitution by doing a string replace on $html_message and using a place marker like ##dateandtime## if you need to.

In this case it's easier to turn off the html editor for the email template and put
<?php echo "Date and time (CET):".date('r'); ?>
into the template directly.

Bob
jmhook 20 Nov, 2008
Hi Bob,

Do you really mean $html_message ? I can't find this variable anywhere!

/Michael
GreyHead 20 Nov, 2008
Hi Michael,

Sorry, that was the old version. Not so easy in the new one. When OnSubmit before is called the Email templates are in an object array $emails. The template is in $emails[i]->template - where 'i' is most likely 0 if you only have one template.

Bob
Max_admin 20 Nov, 2008
Hi Michael,

try to remove the input field from your form HTML and see if it works ?

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jmhook 20 Nov, 2008
Hi Max, Bob!

This method with str_replace works fine!


Field in template (text only email):

The date and time is: ##dateandtime##


Code in Submit-before (part of):

<?php
  $emails[0]->template = str_replace('##dateandtime##',date('r'),$emails[0]->template);
?>


Thanx for your support guys. Keep up the good work!

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

VPS & Email Hosting 20% discount

{item:title} {images:#}