Undefined Index Issue, email template placeholder using check box

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 1, 2018   (RSS)

By gkornbluth - October 30, 2018 - edited: January 2, 2019

Hi All,

PROBLEM SOLVED

I needed to update a form to pass the values of 2 single value check box fields (whether checked or unchecked) to email templates using placeholders and was working on it for most of the day and there’s no joy in Mudville, I’ve still got one issue. thanks to Daniel it's all working now.

If the boxes are checked, they are passed to the email template on submission with no issue, but if they are not checked, they throw ‘undefined index’ errors and the values are not passed.

The checkbox fields are called ‘more_than_one_location_for_practice’ and ‘more_than_one_practitioner_in_practice’

Thanks for looking,

Jerry Kornbluth

REVISED CODE PER DANIEL'S SUGGESTIONS

First I define a concatenated link value for a variable called $addlink with:

// Added 11/1/18 per Daniel at Interactive Tools
$more_than_one_location_for_practice = 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;}

$addLink = "http://dbtproviders.com/cmsAdmin/admin.php?menu=accounts&action=add";
$addLink .= "&username=" .urlencode(@$_REQUEST['username']);
$addLink .= "&email=" .urlencode(@$_REQUEST['email']);
$addLink .= "&contact_first_name=" .urlencode(@$_REQUEST['first_name']);
$addLink .= "&contact_last_name=" .urlencode(@$_REQUEST['last_name']);
$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);

Then lower down on the page I populate the placeholders for the 2 email templates:

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']),
'more_than_one_location_for_practice' => ($more_than_one_location_for_practice),
'more_than_one_practitioner_in_practice' => ($more_than_one_practitioner_in_practice),
'addLink' => $addLink,
)));
$mailErrors = sendMessage($emailHeaders);
if ($mailErrors) { alert("Mail Error: $mailErrors"); }


And

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

'placeholders' => array(
'contact.firstName' => ($_REQUEST['first_name']),
'contact.lastName' => ($_REQUEST['last_name']),
'more_than_one_location_for_practice' => ($more_than_one_location_for_practice),
'more_than_one_practitioner_in_practice' => ($more_than_one_practitioner_in_practice),

)));
$mailErrors = sendMessage($emailHeaders);
if ($mailErrors) { alert("Mail Error: $mailErrors"); }

Then, in the form I’ve been using:

<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 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>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 width="40%" align="left" valign="middle" class="text_font"><b>Is There More Than One Location For This Practice? (Check If Yes)<br />
</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>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - November 1, 2018 - edited: November 1, 2018

Thanks Daniel,

Appreciate the help.

Everything seems too be working as planned now.

I've revised my code above to indicate the changes.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php