USING AN EMAIL TEMPLATE TO CREATE A NEW ACCOUNT RECORD - Apr 10th, 2019


My client needed to validate new listing requests for their on-line directory and then automatically create an account
record with the information from the on-line application form.

To initiate the request, the applicant filled out an on-line form. I used a built in email template to pass the form
values to an admin for approval and to facilitate creating a new account record once the admin had verified their
information.

The problem was that spaces in the text would break the add record request until Dave Edis from interactive Tools came
to the rescue. He suggested that what was needed was to urlencode values that are put in a link. Here’s what I came up
with.

Further, you can't use php variables in an email template, but as Daniel Loewe pointed out, you can use if/else
statements to create a variable to send in as the placeholder instead.

Other challenges were passing dates to the database and passing checkbox arrays that would assign values to a list of
check boxes that gets its initial values from a list field. See the recipe at
http://www.thecmsbcookbook.com/recipedetail.php?Pre-populating-radio-buttons-in-forms-from-a-master-list-568 for more
information on this.

On the page that calls the email template:
In the 'process form' section with error checking, etc., define a variable for passing a date.

$date = date("Y-m-d",mktime(0,0,0,@$_REQUEST['month_1'],@$_REQUEST['day_1'],@$_REQUEST['year_1']));

Then build the link to be passed to the email.

<?php

// add user
if (!$errorsAndAlerts) {
// checkbox pass through code suggested by Daniel Louwe from Interactive Tools 11/1/18
$more_than_one_location_for_practice = 0;
$more_than_one_practitioner_in_practice = 0;
$more_than_one_location_for_practicea = 0;
$more_than_one_practitioner_in_practicea = 0;
if (isset(
$_REQUEST['more_than_one_location_for_practice'] )) {$more_than_one_location_for_practice = 1;}
$more_than_one_practitioner_in_practice = 0;
if (isset(
$_REQUEST['more_than_one_practitioner_in_practice'] )) {$more_than_one_practitioner_in_practice = 1;}
if (
$more_than_one_location_for_practice === 0) {
$more_than_one_location_for_practicea = 'there is only one location for this practice.';
}
elseif (
$more_than_one_location_for_practice === 1) {
$more_than_one_location_for_practicea = 'there are multiple locations for this practice.';
}

if (
$more_than_one_practitioner_in_practice === 0) {
$more_than_one_practitioner_in_practicea = 'there is only one practitioner in this practice.';
}
elseif (
$more_than_one_practitioner_in_practice === 1) {
$more_than_one_practitioner_in_practicea = 'there are multiple practitioner in this practice.';
}
$addLink = "http://my-site.com/cmsAdmin/admin.php?menu=accounts&action=add";
$addLink .= "&username=" .urlencode(@$_REQUEST['username']);
$addLink .= "&email=" .urlencode(@$_REQUEST['email']);
$addLink .= "&password=" .'2AX3Frb' ;
$addLink .= "&first_name=" .urlencode(@$_REQUEST['first_name']);
$addLink .= "&last_name=" .urlencode(@$_REQUEST['last_name']);
$addLink .= "&practice_name=" .urlencode(@$_REQUEST['practice_name']);
$addLink .= "&practice_date=" .urlencode($date);
$addLink .= "&approved=" .'1';
$addLink .= "&practice_street_address=" .urlencode(@$_REQUEST['practice_street_address']);
$addLink .= "&practice_city=" .urlencode(@$_REQUEST['practice_city']);
$addLink .= "&practice_state=" .urlencode(@$_REQUEST['practice_state']);
$addLink .= "&practice_zip=" .urlencode(@$_REQUEST['practice_zip']);
$addLink .= "&practice_phone=" .urlencode(@$_REQUEST['practice_phone']);
$addLink .= "&training_experience=" .urlencode(@$_REQUEST['training_experience']);
$addLink .= "&more_than_one_location_for_practice=" .urlencode(@$more_than_one_location_for_practice);
$addLink .= "&more_than_one_practitioner_in_practice=" .urlencode(@$more_than_one_practitioner_in_practice);
if (!empty(
$_REQUEST['dbt_training_support'] )) {
foreach (
$_REQUEST['dbt_training_support'] as $value) {
$addLink .= '&dbt_training_support[]=' . urlencode($value);
}
}

// send email to Admin
$emailHeaders = emailTemplate_loadFromDB(array(
'template_id' => 'DIRECTORY-LISTING-REQUEST',

'placeholders' => array(
'contact.firstName' => ($_REQUEST['first_name']),
'contact.lastName' => ($_REQUEST['last_name']),
'contact.email' => ($_REQUEST['email']),
'contact.username' => ($_REQUEST['username']),
'practice' => ($_REQUEST['practice_name']),
'street' => ($_REQUEST['practice_street_address']),
'city' => ($_REQUEST['practice_city']),
'state' => ($_REQUEST['practice_state']),
'zip' => ($_REQUEST['practice_zip']),
'phone' => ($_REQUEST['practice_phone']),
'training' => ($_REQUEST['training_experience']),
'more_than_one_location_for_practice' => ($more_than_one_location_for_practicea),
'date1' => ($_REQUEST['practice_date'])
'more_than_one_practitioner_in_practice' => ($more_than_one_practitioner_in_practicea),
'addLink' => $addLink,
)));
$mailErrors = sendMessage($emailHeaders);
if (
$mailErrors) { alert("Mail Error: $mailErrors"); }

// show thanks
$errorsAndAlerts = "
<div class='heading_font' align='center'>THANKS FOR SUBMITTING YOUR REQUEST TO BE INCLUDED IN THE
DIRECTORY
</div>
<div align='center'>

<div class='text_font' align='left'><b>Your directory listing request has been sent successfully.

You'll get an email from us after we've reviewed your request.

Best,

The Directory Team</b></div>
</div>
</div>";
$_REQUEST = array(); // clear form values
$showSignupForm = false;
}

?>

And in the email template I then only had to add the one #addLink# placeholder for the link:

NOTE: I used the free emailOnApproved plugin http://www.thecmsbcookbook/downloads/emailonapproved.zip to send an email
with login information to the applicant if a checkbox called “approved” is checked in their account record, and the
free AlertRecordSaved plugin http://www.thecmsbcookbook/downloads/alertrecordsaved.zip to alert the admin when a profile
is updated.

Because of encrypted passwords, I send a temporary generic password to the approved applicant and they are forced to
change their password on initial log in.
See the recipe at http://www.thecmsbcookbook.com/recipedetail.php?287 for how to accomplish this. (***You must be using
the website membership plugin***)


Hello,

#contact.firstName# #contact.lastName# has submitted a directory listing request for #practice#.


Their address is:#street#
#city#, #state# #zip#


Their phone number is: #phone#


Their email address is: #contact.email#


They've indicated the following training/experience:
#training#

After you've determined that the request is from a valid provider, AND THE PROVIDER IS NOT ALREADY LISTED IN THE
DIRECTORY,

1) click on the link below to create a listing in the directory
2) Make sure that the "Approved" check box is checked in their new listing
3) "Save" the new listing record or it will not be available for updating

NOTE: After they've updated their profile (you'll get an email when they do), and you feel that the information is ready
for release, you'll have to un-hide their listing and re-save the record, or it will not be available in the directory.

If you cannot click on the link below, copy it and paste it into your browser.

#addLink#


The Form that was used for data input for the application contained both text and checkbox fields. Problems with the
checkbox fields were addressed by Daniel Loewe, a programmer at Interactive Tools. The DBT Training/Support field is
feeding it's values as an array, to a list field that gets it's initial data from another table with just the titles of
the support categories. :


<form method="post" action="">
<input type="hidden" name="save" value="1" />
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>What's The Name
Of the Practice
</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="practice_name" id="practice_name" value="<?php echo htmlencode(@$_REQUEST['practice_name']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>The Street Address
Of the Practice
</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="practice_street_address" id="practice_street_address" value="<?php echo
htmlencode(@$_REQUEST['practice_street_address']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>The Suite, Apartment, or Floor
(optional)
</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="practice_room_or_floor" id="practice_room_or_floor" value="<?php echo
htmlencode(@$_REQUEST['practice_room_or_floor']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>The City
</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="practice_city" id="practice_city" value="<?php echo htmlencode(@$_REQUEST['practice_city']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>The State - (2 Letters) </b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text"
type="text"style='text-transform:uppercase' MAXLENGTH="2" name="practice_state" id="practice_state" value="<?php echo
htmlencode(strtoupper(@$_REQUEST['practice_state'])); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>The Zip Code</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="practice_zip" id="practice_zip" value="<?php echo htmlencode(@$_REQUEST['practice_zip']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>The Phone Number
</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="practice_phone" placeholder="Numbers Only Please" id="practice_phone" value="<?php echo
htmlencode(@$_REQUEST['practice_phone']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Is There More Than One Location
For This Practice? (Check If Yes)
</b></td>
<td style="text-align:left" align="left" valign="middle">
<input type="checkbox" name="more_than_one_location_for_practice" value="1" <?php checkedIf('1',
@
$_REQUEST['more_than_one_location_for_practice']); ?> />
</td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font" ><b>First Event Date <span style="color: #C00;
font-weight: bold;">*</span>
</b></td>
<td align="left" valign="middle" class="text_font"><?php
$lowestYear = date("Y");
$highestYear = date('Y', strtotime('+1 years'));
?>
Month:
<select name="month_1">
<?php if (@$_REQUEST['month_1']): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST['month_1']) ?>">
<?php $month1a = @$_REQUEST['month_1'] ?>
<?php echo date("F",strtotime("0000-$month1a"));?></option>
<?php else :?>
<option value=""><?php echo 'Select Month';?></option>
<?php endif ?>
<?php foreach(range(1,12) as $month_1): ?>
<option value="<?php echo $month_1;?>"><?php echo
date("F",strtotime("0000-$month_1"));?></option>
<?php endforeach ?>
</select> Day:
<select name="day_1">
<?php if (@$_REQUEST['day_1']): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST['day_1']) ?>"><?php echo
htmlspecialchars(@$_REQUEST['day_1']) ?></option>
<?php else :?>
<option value=""><?php echo 'Select Day';?></option>
<?php endif ?>
<?php foreach(range(1,31)as $day_1): ?>
<option value="<?php echo $day_1;?>"><?php echo $day_1;?></option>
<?php endforeach ?>
</select> Year:
<select name="year_1">
<?php if (@$_REQUEST['year_1']): ?>
<option value="<?php echo htmlspecialchars(@$_REQUEST['year_1']) ?>"><?php echo
htmlspecialchars(@$_REQUEST['year_1']) ?></option>
<?php else :?>
<option value=""><?php echo 'Select Year';?></option>
<?php endif ?>
<?php foreach (range($lowestYear,$highestYear) as $year_1):?>
<option value="<?php echo $year_1;?>"><?php echo $year_1;?></option>
<?php endforeach?>
</select>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>What's Your First Name</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="first_name" id="first_name" value="<?php echo htmlencode(@$_REQUEST['first_name']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Your Last Name</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="last_name" id="last_name" value="<?php echo htmlencode(@$_REQUEST['last_name']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Enter A Temporary User
Name</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="username" id="username" value="<?php echo htmlencode(@$_REQUEST['username']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Your E-mail Address</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="email" id="email" value="<?php echo htmlencode(@$_REQUEST['email']); ?>" /></td>
</tr>

<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Enter Your E-mail Again</b></td>
<td style="text-align:left" align="left" valign="middle"><input class="text" type="text"
name="email2" id="email2" value="<?php echo htmlencode(@$_REQUEST['email2']); ?>" /></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Is There More Than One DBT Trained
Practitioner In This Practice? (Check If Yes)</b></td>
<td style="text-align:left" align="left" valign="middle"> <input type="checkbox"
name="more_than_one_practitioner_in_practice" value="1" <?php checkedIf('1',
@
$_REQUEST['more_than_one_practitioner_in_practice']); ?> />
</td>
</tr>
<tr>
<td class="text_font" valign="top"><b>DBT Training/Support</b></td>
<td class="text_font"><?php
$fieldname = 'dbt_training_support'; ?>
<?php
if(is_array(@$_REQUEST[$fieldname])){
$fieldValues = $_REQUEST[$fieldname];
}
else{
$fieldValues = explode("\t",trim(@$_REQUEST[$fieldname],"\t"));
}
?>
<?php $idCounter = 0; ?>
<?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?>
<?php $id = "$fieldname." . ++$idCounter; ?>
<input type="checkbox" name="<?php echo $fieldname ?>[]" id="<?php echo $id ?>"
value="<?php echo htmlspecialchars($value) ?>" <?php if(in_array($value,$fieldValues)):?> checked="checked" <?php endif
?>/>
<label for="<?php echo $id ?>">
<?php echo htmlspecialchars($label) ?>
</label>

<?php endforeach ?></td>
</tr>
<tr>
<td width="40%" align="left" valign="middle" class="text_font"><b>Describe Your DBT Training/Experience
(FOR INTERNAL USE ONLY)</b></td>
<td style="text-align:left" align="left" valign="middle"><textarea name="training_experience"
id="training_experience" placeholder="<?php echo
$common_informationRecord['application_training_and_experience_example_text']?>" COLS=50 ROWS=6 ><?php echo
htmlspecialchars(@$_REQUEST['training_experience']); ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" class="text_font" style=" font-weight: bold;" valign="top">
Please check the "I'm not a robot" box below before submitting.

<div class="g-recaptcha" data-theme="light"
data-sitekey="6Lfd5RcTAAAAAJOxR3jJJfn7kfDDo4T8FCBGZKfD"></div></td>
</tr>
<tr>
<td colspan="2" align="center">
<input class="button" type="submit" name="submit" value="SUBMIT YOUR LISTING REQUEST &gt;&gt;"
/></td>
</tr>
</table>
</form>



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service