Jump to content

<br|> shown as plain text


UltraMarkus

Recommended Posts

Hi,

 

First post on this form for me now. Love to see how many posts are made on this site.

 

Well after searching a few hours my problem remains and started to look for some help. Here is what I do:

 

1. Read a textarea with val() and send it trough ajax.

2. In my php file I send the data to a DB.

3. I read the db and uses nl2br to make this all seem worth it.

 

But now there is a funny thing happening, i can see no next lines(breaks).

 

So what did I do, I used to replace all /n/l things to <BR />  with some repeace function. But now when i echo my little tekst there is just a simple <BR /> beeing displayed.

 

Anyone knows someting about this problem?

 

UltraMarkus.

Link to comment
Share on other sites

------------------------------------------

Send form

------------------------------------------

function adSubmit() {
   ajax_request("berichtPlaatsen.php?table=te_koop_aangeboden&naam="+$("#naam").val()+"&email="+$("#email").val()+"&bericht="+$("#bericht").val().replace(/\n/g,"<br>"),"#adToevoegen",berichtGeplaatst);
 }

 

<form>

textarea id="bericht" name="bericht" style="width:99%; height:200px">bericht</textarea>
<input id="submitButton" type="button" onclick="adSubmit()" value="Plaatsen" >

</form>

 

 

-------------------------------------------

When displaying

-------------------------------------------

$bericht = $res[$i]["bericht"];
$bericht = str_replace("<","<",$bericht);
$bericht = str_replace(">",">",$bericht);
echo   $bericht;

 

 

-------------------------------------------

DB STORAGE AFTER PUTTING

line 1

line 2

line 3

--------------------------------------------

 

line 1<br>line 2<br>line 3

 

Perhaps my js replace funtion aint correct.

 

 

If you need more just ask

Link to comment
Share on other sites

Why are you changing it in JS? You really should send the user input AS IS to the server; you should store it (in the database) AS ENTERED by the user. ONLY when you decide to display it in HTML should you change it using nl2br. Then you do not have to jump through these hoops. What if you decide to output the data in some other format (i.e. Plain Text email, RTF Document, etc.)? You would have to convert it from the HTML line-breaks back to newlines (or whatever is appropriate for that format).

Link to comment
Share on other sites

Okay, well the reason why I used it in JS is because my nl2br function didn't work. Normaly when I use a page refresh and send my DB data trough nl2br it catches the whole thing. Now I use this AJAX REQUEST and it fails. Tonight when I'm at home I will check what data is stored in my DB after sending it and not using the JS replace function.

Link to comment
Share on other sites

A bit later then promised.

 

As I use a normal .val() without the replace() extended it results in the db without any sign of /n/l or <BR>. It's just a line without enters.

  ajax_request("berichtPlaatsen.php?table=te_koop_aangeboden&naam="+$("#naam").val()+"&email="+$("#email").val()+"&bericht="+$("#bericht").val(),"#adToevoegen",berichtGeplaatst);
Edited by UltraMarkus
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.