data['parent_last_name']; $house_number = $form->data['house_number']; $street_name = $form->data['street_name']; $street_type = $form->data['street_type']; $city = $form->data['city']; $province = $form->data['province']; $postal_code = $form->data['postal_code']; $home_phone = $form->data['home_phone']; $work_phone = $form->data['work_phone']; $cell_phone = $form->data['cell_phone']; $primary_email = $form->data['primary_email']; $secondary_email = $form->data['secondary_email']; $student_one_name = $form->data['student_one_name']; $student_one_birth = $form->data['student_one_birth']; $student_one_gender = $form->data['student_one_gender']; $student_one_room = $form->data['student_one_room']; $student_one_start_date = $form->data['student_one_start_date']; $student_one_tour_date = $form->data['student_one_tour_date']; $student_one_programs = $form->data['student_one_programs']; $student_two_name = $form->data['student_two_name']; $student_two_birth = $form->data['student_two_birth']; $student_two_gender = $form->data['student_two_gender']; $student_two_room = $form->data['student_two_room']; $student_two_start_date = $form->data['student_two_start_date']; $student_two_tour_date = $form->data['student_two_tour_date']; $student_two_programs = $form->data['student_two_programs']; $current_student = $form->data['current_student']; if ( $primary_email != "" ) {?>This email is to notify you that your enrolment request has been submitted electronically via the website. Please keep this email for your records.This email is to notify you that an enrolment form has been submitted electronically via the website.Current Student (Parent First Name: Parent Last Name: Address: Home Phone: Work Phone: Cell Phone: Primary Email: Secondary Email: Student #1Student #1 Name: Birth Date: Gender: Room: Start Date Preferred: Tour Date Preferred: Selected Program(s): Student #2Student #2 Name: Birth Date: Gender: Room: Start Date Preferred: Tour Date Preferred: Selected Program(s): Thanks"> Email Template Pre Processing - Forums

Forums

Email Template Pre Processing

chrono_time 08 May, 2013
Hello,

We are attempting to use php to pre-process a form email template's html before sending to both the admin and the user. The script is designed to strip empty fields before sending. We've looked at and tried to implement solutions from the other similar posts in this forum but can't seem to get it working. The form submits successfully to the database, there are no php errors displayed in the browser, and both emails send successfully (one to the applicant and one to the site admin), but there are blank form fields in the email still. I've posted the code below to show what we are pasting into the "On Submit Code - before sending email" field. Also, I can't seem to find where the php error logs are stored in the chronoforms component.


<?php
  $parent_first_name = $form->data['parent_first_name'];
  $parent_last_name = $form->data['parent_last_name'];
  $house_number = $form->data['house_number'];
  $street_name = $form->data['street_name'];
  $street_type = $form->data['street_type'];
  $city = $form->data['city'];
  $province = $form->data['province'];
  $postal_code = $form->data['postal_code'];
  $home_phone = $form->data['home_phone'];
  $work_phone = $form->data['work_phone'];
  $cell_phone = $form->data['cell_phone'];
  $primary_email = $form->data['primary_email'];
  $secondary_email = $form->data['secondary_email'];
  $student_one_name = $form->data['student_one_name'];
  $student_one_birth = $form->data['student_one_birth'];
  $student_one_gender = $form->data['student_one_gender'];
  $student_one_room = $form->data['student_one_room'];
  $student_one_start_date = $form->data['student_one_start_date'];
  $student_one_tour_date = $form->data['student_one_tour_date'];
  $student_one_programs = $form->data['student_one_programs'];
  $student_two_name = $form->data['student_two_name'];
  $student_two_birth = $form->data['student_two_birth'];
  $student_two_gender = $form->data['student_two_gender'];
  $student_two_room = $form->data['student_two_room'];
  $student_two_start_date = $form->data['student_two_start_date'];
  $student_two_tour_date = $form->data['student_two_tour_date'];
  $student_two_programs = $form->data['student_two_programs'];
  $current_student = $form->data['current_student'];

  if ( $primary_email != "" ) {
?>
<p>This email is to notify you that your enrolment request has been submitted electronically via the website. Please keep this email for your records.
</p>
<?php
  } else {
?>
<p>This email is to notify you that an enrolment form has been submitted electronically via the website.
</p>
<?php
  }
  if ( $current_student != "" ) {
?>
<p>Current Student (<?=$current_student?></p>
<?php
  } else {
?>
<p>
<?php
    if ( $parent_first_name != "" ) {
?>
<strong>Parent First Name: </strong><?=$parent_first_name;?><br />
<?php
    }
    if ( $parent_last_name != "" ) {
?>
<strong>Parent Last Name: </strong><?=$parent_last_name;?><br />
<?php
    }
    if ( $street_name != "" ) {
?>
<strong>Address: </strong><?=($house_number != "")?$house_number:""?> <?=($street_name != "")?$street_name:""?> <?=($street_type != "")?$street_type:""?><br />
<?=($city != "")?$city:""?><?=($province != "")?", ".$province:""?> <?=($postal_code != "")?$postal_code:""?><br />
<?php
    }
    if ( $home_phone != "" ) {
?>
<strong>Home Phone: </strong><?=$home_phone?> <br />
<?php
    }
    if ( $work_phone != "" ) {
?>
<strong>Work Phone: </strong><?=$work_phone?> <br />
<?php
    }
    if ( $cell_phone != "" ) {
?>
<strong>Cell Phone: </strong><?=$cell_phone?><br />
<?php
    }
    if ( $primary_email != "" ) {
?>
<strong>Primary Email: </strong><?=$primary_email?><br />
<?php
    }
    if ( $secondary_email != "" ) {
?>
<strong>Secondary Email: </strong><?=$secondary_email?>
<?php
    }
?>
</p>
<?php
  }
  if ( $student_one_name != "" ) {
?>
<p>
<strong>Student #1</strong><br />
<strong>Student #1 Name: </strong><?=$student_one_name?><br />
<?php
    if ( $student_one_birth != "" ) {
?>
<strong>Birth Date: </strong><?=$student_one_birth?><br />
<?php
    }
    if ( $student_one_gender != "" ) {
?>
<strong>Gender: </strong><?=$student_one_gender?><br />
<?php
    }
    if ( $student_one_room != "" ) {
?>
<strong>Room: </strong><?=$student_one_room?><br />
<?php
    }
    if ( $student_one_start_date != "" ) {
?>
<strong>Start Date Preferred: </strong><?=$student_one_start_date?><br />
<?php
    }
    if ( $student_one_tour_date != "" ) {
?>
<strong>Tour Date Preferred: </strong><?=$student_one_tour_date?><br />
<?php
    }
    if ( $student_one_programs != "" ) {
?>
<strong>Selected Program(s): </strong><?=$student_one_programs?>
<?php
    }
?>
</p>
<?php
  }
  if ( $student_two_name != "" ) {
?>
<p>
<strong>Student #2</strong><br />
<strong>Student #2 Name: </strong><?=$student_two_name?><br />
<?php
    if ( $student_two_birth != "" ) {
?>
<strong>Birth Date: </strong><?=$student_two_birth?><br />
<?php
    }
    if ( $student_two_gender != "" ) {
?>
<strong>Gender: </strong><?=$student_two_gender?><br />
<?php
    }
    if ( $student_two_room != "" ) {
?>
<strong>Room: </strong><?=$student_two_room?><br />
<?php
    }
    if ( $student_two_start_date != "" ) {
?>
<strong>Start Date Preferred: </strong><?=$student_two_start_date?><br />
<?php
    }
    if ( $student_two_tour_date != "" ) {
?>
<strong>Tour Date Preferred: </strong><?=$student_two_tour_date?><br />
<?php
    }
    if ( $student_two_programs != "" ) {
?>
<strong>Selected Program(s): </strong><?=$student_two_programs?>
<?php
    }
?>
</p>
<?php
  }
?>


Thanks
GreyHead 09 May, 2013
Hi chrono_time,

There's nothing in your code that will add it to the email template. I think it will just output to the browser. You need to build your template in a string and then save it to say $form->data['email_template'] then add {email_template} to the Email template box in the action.

The PHP Error logs are wherever your server keeps them, there are no specific ChronoForms PHP Error logs. The PHP looks OK - though quite a lot of it does nothing useful.

Bob
chrono_time 10 May, 2013
Hi Bob,

Thanks for your response. We tried the following code (and entered "{email_template}" into the template fields under the "Emails Templates" tab. When we submit the form, the email the administrator and user receive just shows "{email_template}". Are we missing something?


<?php
  $parent_first_name = $form->data['parent_first_name'];
  $parent_last_name = $form->data['parent_last_name'];
  $house_number = $form->data['house_number'];
  $street_name = $form->data['street_name'];
  $street_type = $form->data['street_type'];
  $city = $form->data['city'];
  $province = $form->data['province'];
  $postal_code = $form->data['postal_code'];
  $home_phone = $form->data['home_phone'];
  $work_phone = $form->data['work_phone'];
  $cell_phone = $form->data['cell_phone'];
  $primary_email = $form->data['primary_email'];
  $secondary_email = $form->data['secondary_email'];
  $student_one_name = $form->data['student_one_name'];
  $student_one_birth = $form->data['student_one_birth'];
  $student_one_gender = $form->data['student_one_gender'];
  $student_one_room = $form->data['student_one_room'];
  $student_one_start_date = $form->data['student_one_start_date'];
  $student_one_tour_date = $form->data['student_one_tour_date'];
  $student_one_programs = $form->data['student_one_programs'];
  $student_two_name = $form->data['student_two_name'];
  $student_two_birth = $form->data['student_two_birth'];
  $student_two_gender = $form->data['student_two_gender'];
  $student_two_room = $form->data['student_two_room'];
  $student_two_start_date = $form->data['student_two_start_date'];
  $student_two_tour_date = $form->data['student_two_tour_date'];
  $student_two_programs = $form->data['student_two_programs'];
  $current_student = $form->data['current_student'];

  $emailbody = ""
  if ( $primary_email != "" ) {
    $emailbody .= "<p>This email is to notify you that your enrolment request has been submitted electronically. A staff member will be in contact with you shortly.</p>";
  } else {
    $emailbody .= "<p>This email is to notify you that an enrolment form has been submitted electronically.</p>";
  }
  if ( $current_student != "" ) {
    $emailbody .= "<p>Current Student ($current_student)</p>";
  } else {
  $emailbody .= "<p>";
    if ( $parent_first_name != "" ) {
      $emailbody .= "<strong>Parent First Name: </strong>$parent_first_name;<br />";
    }
    if ( $parent_last_name != "" ) {
      $emailbody .= "<strong>Parent Last Name: </strong>$parent_last_name;<br />";
    }
    if ( $street_name != "" ) {
      $emailbody .= "<strong>Address: </strong>"
      if ($house_number != "") {
        $emailbody .= $house_number;
      }
      if ($street_name != "") {
        $emailbody .= $street_name;
      }
      if ($street_type != "") {
        $emailbody .= $street_type;
      }
      $emailbody .= "<br />";
      if ($city != "") {
        $emailbody .= $city;
      }
      if ($province != "") {
        $emailbody .= ", ".$province;
      }
      if ($postal_code != "") {
        $emailbody .= $postal_code;
      }
      $emailbody .= "<br />";
    }
    if ( $home_phone != "" ) {
      $emailbody .= "<strong>Home Phone: </strong>$home_phone <br />";
    }
    if ( $work_phone != "" ) {
      $emailbody .= "<strong>Work Phone: </strong>$work_phone <br />";
    }
    if ( $cell_phone != "" ) {
      $emailbody .= "<strong>Cell Phone: </strong>$cell_phone <br />";
    }
    if ( $primary_email != "" ) {
      $emailbody .= "<strong>Primary Email: </strong>$primary_email<br />";
    }
    if ( $secondary_email != "" ) {
      $emailbody .= "<strong>Secondary Email: </strong>$secondary_email";
    }
    $emailbody .= "</p>";
  }
  if ( $student_one_name != "" ) {
    $emailbody .= "<p><strong>Student #1</strong><br /><strong>Student #1 Name: </strong>$student_one_name<br />";
    if ( $student_one_birth != "" ) {
      $emailbody .= "<strong>Birth Date: </strong>$student_one_birth<br />";
    }
    if ( $student_one_gender != "" ) {
      $emailbody .= "<strong>Gender: </strong>$student_one_gender<br />";
    }
    if ( $student_one_room != "" ) {
      $emailbody .= "<strong>Room: </strong>$student_one_room<br />";
    }
    if ( $student_one_start_date != "" ) {
      $emailbody .= "<strong>Start Date Preferred: </strong>$student_one_start_date<br />";
    }
    if ( $student_one_tour_date != "" ) {
      $emailbody .= "<strong>Tour Date Preferred: </strong>$student_one_tour_date<br />";
    }
    if ( $student_one_programs != "" ) {
      $emailbody .= "<strong>Selected Program(s): </strong>$student_one_programs";
    }
    $emailbody .= "</p>";
  }
  if ( $student_two_name != "" ) {
    $emailbody .= "<p><strong>Student #2</strong><br /><strong>Student #2 Name: </strong>$student_two_name<br />";
    if ( $student_two_birth != "" ) {
      $emailbody .= "<strong>Birth Date: </strong>$student_two_birth<br />";
    }
    if ( $student_two_gender != "" ) {
      $emailbody .= "<strong>Gender: </strong>$student_two_gender<br />";
    }
    if ( $student_two_room != "" ) {
      $emailbody .= "<strong>Room: </strong>$student_two_room<br />";
    }
    if ( $student_two_start_date != "" ) {
      $emailbody .= "<strong>Start Date Preferred: </strong>$student_two_start_date<br />";
    }
    if ( $student_two_tour_date != "" ) {
      $emailbody .= "<strong>Tour Date Preferred: </strong>$student_two_tour_date<br />";
    }
    if ( $student_two_programs != "" ) {
      $emailbody .= "<strong>Selected Program(s): </strong>$student_two_programs";
    }
    $emailbody .= "</p>";
  }
  $form->data['email_template'] = $emailbody;
?>


Thanks,
Jesse
GreyHead 10 May, 2013
Hi Jesse,

That should work OK. Is the Custom Code action with this PHP before the Email action?

Bob
chrono_time 10 May, 2013
Hi Bob,

Yes, we are pasting the code into the "On Submit code - before sending email:" field. This is an installation of Chronoforms on Joomla 1.5.22.

Thanks,
Jesse
GreyHead 10 May, 2013
Hi chrono_time,

If you are using ChronoForms v3 then please try replacing this line
  $form->data['email_template'] = $emailbody;
with
  JRequest::setVar('email_template', $emailbody);

Bob
chrono_time 14 May, 2013
We are getting nowhere with this.
GreyHead 14 May, 2013
Hi Jesse,

Yes . . . and . . . ?

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