Forums / General Questions / Plain text is adding HTML tags

Plain text is adding HTML tags

Locked
Results 1 to 14 of 14
This thread is locked. New replies are disabled.
07 Jul 2010, 16:58
#1
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Plain text is adding HTML tags

hi
I'm trying to use the plain text for product descriptions and when i preview it; it shows fine, but when i look at my product in the catalog i notice html "<br/>" tags in the description, for every time i pressed enter (it acts like a wysiwyg) so i can not write any script because it keeps on adding unwanted tags :(

i'm running 1.3.9, php5, mySql5,
and I'm hosted by GoDaddy
07 Jul 2010, 19:52
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Plain text is adding HTML tags

You haven't said anything about how you're adding this text, but I suspect that what is happening is that Zen Cart is converting the end of line characters in your plain text into <br/> tags.

It has to really, as the XHTML used to render your plain text in a browser doesn't recognise end of line characters. The XHTML equivalent is a <br/> tag and so is appropriate to substitute, otherwise your entire product description would come out as a single line.

I'm puzzled by your comment about being unable to write script. Your product descriptions aren't the place for script. Maybe if you could expand on what you're trying to do, we can help more.
07 Jul 2010, 21:06
#3
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Re: Plain text is adding HTML tags

Thanks for replying

I'm entering the characters only myself no pasting or copying
Ex:
this is text
this is some more

should give you "this is text this is some more"
but it gives you

"this is text
this is some more"


and in the source i can see added <br>tags :frusty:
this should not happen in plain text mode

here is the url of the page
https://www.voucher-checks.com/computer-deposit-slips-p-86.html

The reason why I need to be able to add client-side scripts like JS or inline CSS is quite simple, i need some java script and css for a few particular pages and not for the whole site
07 Jul 2010, 23:56
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Plain text is adding HTML tags

The products_description is managed by:
  $products_description = (!preg_match('/(<br|<p|<div|<dd|<li|<span)/i', $product_info->fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']);


So if anything is contained in the products_description then the products_description is used, as is ...

if nothing is in the products_description then the nl2br is adding the line breaks as entered ... in essence the enters you hit in plain text are doing just what you said when you hit enter ...
08 Jul 2010, 08:42
#5
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Plain text is adding HTML tags

Nice job on the site. Very clean and professional looking. Very well suited to the products you're selling.

You have three options.
  1. You could remove the nl2br function call that Ajeh has highlighted and deal with any fallout elsewhere.
  2. You could selectively remove this function by wrapping it in an if ... else ... statement so that it isn't called for the specific products that you want to handle differently.
  3. You could use the Zen Cart's built-in javascript and css loading. These are documented in detail the respective readme files that come in the docs folder of a Zen Cart download. But in summary you can load css for individual products and javascript for a specific page (so you'd still need an if ... else ... statement if you needed it not to be loaded for other products).
08 Jul 2010, 16:54
#6
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Re: Plain text is adding HTML tags

thanks you both Ajeh and kuroi

please bare with me, lets not talk about "valid syntax" for now.
if i use white space to it should not show in the browser; however in the source code it will. line breaks are not carriage renters in plain text; they are displayed as a single "nbsp" (non breaking space).

so how can this be? both have the same descriptions
http://www.aacellphone.com/test-some-stuff-p-133.html

https://www.voucher-checks.com/computer-deposit-slips-p-86.html


non p test: top line
middle line
bottom line

<style type="text/css">
<!--
@import "https://voucher-checks.com/includes/templates/vc/css/reset_att.css";

-->
</style>


and the out put are really different

the first acts as it should and the second adds 8 break tags and screws up my code:frusty:

nl2br is not at fault, or i think so HELP!!
08 Jul 2010, 17:45
#7
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Re: Plain text is adding HTML tags

i checked in the database
and they both are represented exactly the same
like this

(133,1,'test some stuff','non p test: top line\r\nmiddle line\r\nbottom line\r\n\r\n<style type=\"text/css\">\r\n<!--\r\n@import \"https://voucher-checks.com/includes/templates/vc/css/reset_att.css\";\r\n\r\n-->\r\n</style>','',4)

how come they appear so differently????
08 Jul 2010, 18:05
#8
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Posts:
19,793
Plugin Contributions:
2

Re: Plain text is adding HTML tags

One reason is that the Computer Deposit Slips is a product info page, while the 'test some stuff' is a product listing. Zencart strips HTML from the product listing description by default.

That doesn't explain why the HTML is applied to the description when entered as Plain Text, but my bone-stock test site does the same thing.
08 Jul 2010, 19:03
#9
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Re: Plain text is adding HTML tags

thanks
but NO its not a listing

it looks like a listing because i added an add to cart but its a product info page

the listing is
http://www.aacellphone.com/verizon-usb-cards-c-9.html

the info is
http://www.aacellphone.com/test-some-stuff-p-133.html

BTW i do not have problems in the listing, nor do i have any problems when i preview the product in the admin (before updating)

i have an ugly feeling about it cus 1.3.8 gets it fine and 1.3.9 is giving me problems , the only thing that i added to the voucher-checks site is CKeditor but its terned off and i'm working in plain text mode

if i add a <p>tag to the description like this

non p test: top line
middle line
bottom line

<style type="text/css">
<!--
@import "https://voucher-checks.com/includes/templates/vc/css/reset_att.css";

-->
</style>

it gets it right
https://www.voucher-checks.com/test-some-stuff2-p-87.html
08 Jul 2010, 19:20
#10
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Posts:
19,793
Plugin Contributions:
2

Re: Plain text is adding HTML tags

You're right, sorry.

Another 'clue' is the fact that looking at the pages using Web Developer, the product description of 'test some stuff' is inside #product_details_wrapper, and the other isn't, so it may be a template thing.
08 Jul 2010, 19:31
#11
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Plain text is adding HTML tags

Correct Zen Cart behaviour in 1.3.9 is to add br tags to the product description where a production description has no other html.

This was added to deal with a specific issue where some users were neither using an HTML editor, nor inserting their own HTML. So their product descriptions were all screwed up.

You want it to act the opposite way, in order to do something which it's not designed to do. That's fine. This is open source and you can change it to work however you want, and we've told you the change to make it work as you want.

For good measure, as an alternative, we've also told you how to achieve what you want to achieve the Zen Cart way.

So I'm confused as to what more you want. :dontgetit
08 Jul 2010, 20:00
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: Plain text is adding HTML tags

And I'm unsure why you're importing css via a product description.
If you need custom CSS on a per-page or even a per-product basis, there is built-in functionality to handle that for you, making it unnecessary to stuff it into product descriptions.
See the /docs/ folder of your Zen Cart files.
08 Jul 2010, 20:57
#13
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Re: Plain text is adding HTML tags

Correct
but i have about 70 pages/products that must have a different css
do i have to create 70 or so css.pages?

and where do i find the
$products_description = (!preg_match('/(<br|<p|<div|<dd|<li|<span)/i', $product_info->fields['products_description']) ? nl2br($product_info->fields['products_description']) : $product_info->fields['products_description']);

to tern it off

I appreciate your time, all of you
08 Jul 2010, 21:15
#14
evelt avatar

evelt

Zen Follower

Join Date:
Nov 2009
Posts:
170
Plugin Contributions:
1

Re: Plain text is adding HTML tags

as for the css I'm going to do is this:
create a dump category and place all products in it, so i can design a special CSS for that cat (ie. c_12_23.css)
than I'll link it all to the right categories:blush:

as for PLAIN text, I'm going to tern off this added feature; if any one can tell me where the code resides, hence the name plain text :)