Spaces in placeholder text entries
5 posts by 2 authors in: Forums > CMS Builder
Last Post: May 18, 2017 (RSS)
By gkornbluth - May 17, 2017
Hi All,
I’m using an email template to create an account record and I’m running into a problem with spaces in text entries.
I realize that I can’t have spaces in the placeholder text, so I’m using preg_replace to replace all spaces with an underscore.
The problem is that I’d rather have the spaces in the actual contents of the text fields and text boxes created in the record, so I don’t have to do another preg_replace everywhere that they appear.
Any thoughts?
Here’s the code I’m using on the form page:
// add user
if (!$errorsAndAlerts) {
@$_REQUEST['practice_name'] = preg_replace("/ /", '_', @$_REQUEST['practice_name']);
@$_REQUEST['first_name'] = preg_replace("/ /", '_', @$_REQUEST['first_name']);
@$_REQUEST['last_name'] = preg_replace("/ /", '_', @$_REQUEST['last_name']);
@$_REQUEST['practice_street_address'] = preg_replace("/ /", '_', @$_REQUEST['practice_street_address']);
@$_REQUEST['practice_city'] = preg_replace("/ /", '_', @$_REQUEST['practice_city']);
@$_REQUEST['practice_state'] = preg_replace("/ /", '_', @$_REQUEST['practice_state']);
@$_REQUEST['practice_zip'] = preg_replace("/ /", '_', @$_REQUEST['practice_zip']);
@$_REQUEST['practice_phone'] = preg_replace("/ /", '_', @$_REQUEST['practice_phone']);
@$_REQUEST['training_experience'] = preg_replace("/ /", '_', @$_REQUEST['training_experience']);
// 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'],
)));
$mailErrors = sendMessage($emailHeaders);
if ($mailErrors) { alert("Mail Error: $mailErrors"); }
And the Email Template:
Thanks for looking...
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Dave - May 18, 2017
Hi Jerry,
The issue is that you need to urlencode values that you put in a link. You can use the PHP urlencode() function for this.
The easiest might be to build up your link in PHP and then pass it as one value to the placeholders array.
$addLink = "http://my-site.com/cmsAdmin/admin.php?menu=accounts&action=add";
$addLink .= "&username=" .urlencode(@$_REQUEST['username']);
$addLink .= "&email=" .urlencode(@$_REQUEST['email']);
// and so on...
And then add it to your placeholders
Let me know if that works for you.
interactivetools.com
By gkornbluth - May 18, 2017
Thanks Dave,
I'm assuming that you're suggesting changing the code in the email template, but won't be able to look at it until tomorrow morning.
Hopefully I won't have too much difficultly getting this to work.
I'll let you know and post the result.
Best,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Dave - May 18, 2017
Yea, you'd either need to change the code in the email template to include a link with urlencoded values, or urlencode all the placeholders before you pass them in. But if you urlencoded all the placeholders before you passed them to the function then you wouldn't be able to display them as text because they'd look "like%20this". So probably the first option would be best.
Let me know how it goes.
interactivetools.com
By gkornbluth - May 18, 2017 - edited: May 19, 2017
Hi Dave,
Thanks for all your help!
Once I figured out all the syntax it worked like a charm. Here's what I came up with:
In the page that calls the email template:
<?php
// add user
if (!$errorsAndAlerts) {
$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 .= "&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']);
// 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']),
'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<br />IN THE DIRECTORY<br />
</div>
<div align='center'>
<br />
<div class='text_font' align='left'><b>Your directory listing request has been sent successfully.<br />
<br />
You'll get an email from us after we've reviewed your request.<br />
<br />
Best, <br />
<br />
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 #addLink# placeholder in place of the link and code I originally used:
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/expeience:
#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#
Hope it proves useful to someone.
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php