Jump to content
Sign in to follow this  
Dirty Butter

How to allow line breaks Customers can use in Gift Messages

Recommended Posts

I basically cloned the packing slip files so I can give customers a way to write a gift message and send a packing slip without prices displayed.

This works very well for short messages. But sometimes they write enough to wrap to a second line and doesn't "look right".

My layout centers their message under our logo in a large bold font.

Here's one that looks odd all in one wrapped line:

Happy 1st Birthday to my beautiful daughter, xxx!! I hope you love and cherish your Nicky!!! Love, mommy

For the few that are this long I have been going into phpMyAdmin and adding breaks:

Happy 1st Birthday to my beautiful daughter, xxxx!!
I hope you love and cherish your Nicky!!!
Love, mommy

Is there any fairly easy coding change to give the customer a way to create the line breaks?

If not, I'll keep doing what I am doing. This happens rarely enough to not be that much trouble.

 

 

Share this post


Link to post
Share on other sites

A key aspect to be aware of is that text, when displayed onto an HTML page, will have any line break characters ignored, but HTML will only respect the <br> tag.

So, when you say you have been adding breaks, what kind of breaks, exactly?

Share this post


Link to post
Share on other sites

This is for the print packing slip that goes in every order. I used <br> to create lines- quick and easy, rather than <p> </p>.

Share this post


Link to post
Share on other sites

So, we need to use the PHP function nl2br() at either:
* just before assigning the text to a Smarty variable for the printout, or
* just before sending the data to the database.

Share this post


Link to post
Share on other sites

This is my code for the Gift Enclosure section:

	  {if !empty($order.customer_message)}
<p><center>
<!--	  <div id=" ">Message from {$order.first_name}: <h3> {$order.customer_message|nl2br}</div></h3> -->
          <div id=" "><h2> {$order.customer_message|nl2br}</div></h2>
</center></p>
	  {/if}

So it already has the |nl2br| - maybe in the wrong place?

 

Share this post


Link to post
Share on other sites

That should work. But it depends on what the actual type of new line that is in the text.

When looking directly at the value in the database table, what do you see immediately after the xxxx!!?

Do you see that the line actually breaks, or do you see \r\n and the line actually does not break?

The PHP function nl2br() adds a <br> tag after only existing \r\n that is in the string. (The \r\n is an escape code using visible characters which represent, but are not the same as, the actual control codes of a carriage return (byte value 13) and line feed (byte value 10). So, if the string has actual carriage returns and line feeds, as opposed to \r\n escape codes, then nl2br() won't work.

(Note, however, the </h2> tag should be ahead of the </div> tag. Also, you don't need the <div></div> tags anyway.)

 

Share this post


Link to post
Share on other sites

I created a test order and pushed enter to get different lines shown. The order_summery table customer_message field has just what I typed in on the customer's order page:

Quote

For you
Love, Mama

And the packing slip works! I guess I never had actually tested it as a customer, because they never have used different lines.

So the problem is not with code, but a way to explain this method to the customer.

Sorry for wasting your time!

Share this post


Link to post
Share on other sites

This is not what I expected.

Please do this: view the contents of CubeCart_order_summary, customer_message column. Have the utility (phpMyAdmin?) show the contents as a hex view. (Not sure how to do that in phpMyAdmin.) Verify the hex values (??) after the first seven bytes:

46 6F 72 20 79 6F 75 ?? ?? ??

Share this post


Link to post
Share on other sites

Here's what resulted when I saved the custumer_message text entry as Hex and saved it:

 

466F7220796F75 - here's the ???? part - 0D0A4C6F76652C204D616D61

Share this post


Link to post
Share on other sites

Good. The 0D0A part is what nl2br() is looking for.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...