Link to home
Start Free TrialLog in
Avatar of irwells
irwells

asked on

Text formatting

Hi, I have created a web page that allows the selling of antique furniture. The website in made using php as the front end and MySql as the database.
I have created an Editing suite for the client to add/amend and delete items on the website. The issue we are having is in the text areas, we have to use HTML break tags as line breaks. This is very frustrating for my client and has asked me to find an alternative solution to using the HTML tags?
My question is, is there a way of creating a class/script that will add the HTML tags automatically and format the text in the textboxes?

screenshot1 is a screenshot of the textboxes in the editing suite.
screenshot2 is the screenshot of the website. User generated image User generated image
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But if you want a more comprehensive solution (albeit a little more work) learn about TinyMCE.  It is the textarea processor used by WordPress.  Allows lots of easy client-side text formatting, etc.  The only problem I have had with TinyMCE occurred when clients copied from Word documents.  A bit of client education solved that issue.
Avatar of Tom Beck
It seems to me the problem is capturing the new lines in the textarea. I don't understand how nl2br() can help here. I can think of only two possibilities aside from third party add-ons.

1. Capture the carriage returns using javascript and convert them to <br /> before submitting. This is problematic because clinking Enter can also submit the for if the submit button has focus.

2. Use a single line textbox and provide a button below it that says "New Line". The client can add new lines as desired. You can add new textboxes using the javascript DOM and assemble the inputs client side, appending <br />s between each textbox value, before submitting the form.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of irwells
irwells

ASKER

wow, thanks guys for a quick responce.

I will play around with my code tomorrow and see if it work.

Will keep you posted.

Many Thanks
Ian
Avatar of irwells

ASKER

hi guys,
I have tried both str_replace and nl2br() on $POST and $row on the text areas and both work beautifully. I have decided to use nl2br() on $row.

$description=nl2br($row["description"]);
$dimension=nl2br($row["dimension"]);

this is because using nl2br() or str_replace on $POST adds the <br /> marks to the text in the database and shows the <br /> marks when i update and refreah the Editing page.

The only issue i have is that my tooltip does not work using nl2br() or str_replace. For some stange reason the tooltip will only diplay if the text is formatted in one single line:

Height 46.5cm<br />Diameter 25cm

and not formatted in multiable lines:

Height 46.5cm
Diameter 25cm<br />

can anyone give advive on this???

Ian