Forums

Serial Number on emails

rlab 20 Dec, 2011
Hi,

I want to have a text file that contains a serial number for submitted email. I want to have this serial number show up in the subject line for the emails to the client and user, but I also want to be able to add the serial number in the text of the email message to the user.

I have been able to get the serial number and add it to the subject lines, but I can't get it to use in the message text.

I added a hidden field called count inot the form.
In the On Submit event I added a Custom code block. This is where I get the count from the file. What I tried to do is update the count field, so it could be used in the email message text. Like so:


<?php
// Change the Subjects to have the site name in them
  $name = JRequest::getString('first_name', '', 'post') . ' ' . JRequest::getString('last_name', '', 'post');
  // Get the hidden field that the counter goes into
  $count = JRequest::getString('count', '', 'post');

// Check for an RLAB email address
  $email = JRequest::getString('email', '', 'post');
  if (strpos($email, '@doamin.com') === false) {
    $form->data['toemail']  = 'joomla@domain.com';
    $form->data['bccemail'] = 'bcc@domain.ca';
    // Add code to read count file & update it
    $count = JFile::read('/home/sccsnew/public_html/_private/count.txt');
    $count++;
    JFile::write('/home/sccsnew/public_html/_private/count.txt', $count);       
  } else {
    // Found a RLAB email address, so change the To email address
    $form->data['toemail']  = $email;
    $form->data['bccemail'] = ''; 
    $count = 'TEST';        
  }
  $subject = "Quick Form: $count on domain.ca from: $name";
  $form->data['subject2']  = $subject;
  $form->data['subject3'] = "Quick Form: $count submission on domain.ca";
  JRequest::setVar('count', $count);  // Update the hidden count variable for use in the email text
?>


I gather that the email text already has had the variables replaced by the time this code gets executed which is why the {count} doesn't show up with either a number form the count.txt file or TEST. So, where can I put the code to get the count.txt data, update it before the variables get replaced in the email text?

The email text has:
Worksheet #: {count}
in it.

Thank you for your help
GreyHead 21 Dec, 2011
Hi rlab,

Using JRequest::setVar(); doesn't work in CFv4 (it does in CFv3). Max has changed the code to only read data from the $form->data array after it is initially loaded. If you use
$form->data['count'] = $count;
then the curly brackets syntax should work OK in the Email template.

This is general advice for CFv4: to pass data between actions in the same event add it to the $form->data array (or declare it as global if that isn't desirable for some reason).

Bob
rlab 21 Dec, 2011
Hi,

Thanks again for your help. That works perfectly.
This topic is locked and no more replies can be posted.