Forums

Changing Code for V3.1

dwayne 05 Mar, 2009
I had this code for version 2.3.9 on Joomla 1.x, now I'm moving the site to Joomla 1.5 and using version 3.1rc2.
I setup the new form so that it sends plain text email. So how change the following code to use what is available in 3.1?
A few things are being done:
1. grabs the requestid from a file and increments it
2. it takes the requestid and appends to the subject line
3. the requestid is substituted into the text of the email
4. the date is substituted into the text of the email
5. it write the requestid back to the file

This is code in the "On Submit code - before sending email" section:

<?php
// handle request number
$myFile = "/home2/openspar/www/requestnum.txt";
// read number from file
$handle = fopen($myFile, 'r');
$serial = fread($handle, 3);
fclose($handle);
$serial++;
// update requestid in email template
$_POST['requestid'] = date('dmy').$serial;  
$requestid = date('dmy').$serial;
$requestdate = date('r');
$html_message = str_replace("##requestid##", $requestid, $text_message);
$html_message = str_replace("##requestdate##", $requestdate, $text_message);
$rows[0]->emailsubject .= $requestid;
$data = sprintf("%'03u", $serial) . "\n";
echo $data;
// write updated request number back into file
$Handle = fopen($myFile, 'w');
fwrite($Handle, $data);
fclose($Handle);

// remove line breaker
$html_message = str_replace("\r\n", "", $html_message);
?>


This is my email template:

|####requestid####|{institution_name}|{institution_address}|{institution_city}|{institution_state}|{institution_country}|{institution_zipcode}|{name}|{address}|{city}|{state}|{country}|{zipcode}|{email}|{phone}|{affiliation}|{numboards}|{justification}|##requestdate##|{opt-in}|
GreyHead 05 Mar, 2009
Hi dwayne,

I think that the main difference is that the email body is now in $emails[0]->template at the time the OnSubmit Before code runs.

Note that the [0] is an index as there can be several emails & templates. If you have more than one [email on a single form] then there is a bug that makes the index unreliable.

Bob

Later : added [email on a single form]
dwayne 05 Mar, 2009
Thanks, I do have more than one form, so its there an alternative to using the index [0]? What is unreliable? Do I need to find the right index?
Max_admin 05 Mar, 2009
Hi dwayne,

more than 1 form is fine, but more than 1 email per the form then you may fall in that issue.

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dwayne 05 Mar, 2009
What is the variable for the subject line?
GreyHead 05 Mar, 2009
Hi dwayne

$emails[0]->subject I think.

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