Jump to content

How to allow line breaks Customers can use in Gift Messages


Dirty Butter

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.

 

 

Link to comment
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?

Link to comment
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?

 

Link to comment
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.)

 

Link to comment
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!

Link to comment
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 ?? ?? ??

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...