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:

http://my-site.com/cmsAdmin/admin.php?menu=accounts&action=add&username=#contact.username#&email=#contact.email#&password=2QB3Lr&hidden=1&contact_first_name=#contact.firstName#&contact_last_name=#contact.lastName#&practice_name=#practice#&approved=1&practice_street_address=#street#&practice_city=#city#&practice_state=#state#&practice_zip=#zip#&practice_phone=#phone#&training_experience=#training#



Thanks for looking...

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

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.

Dave Edis - Senior Developer

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

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 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.

Dave Edis - Senior Developer

interactivetools.com