Jump to content

Hiding br tags in textarea (flatfile-editinplace cms)


wizr

Recommended Posts

I recently made a flatfile cms (+ edit in place).  Here's an example of how it shows the <br>'s when hitting enter. The password is demo. Now when you click inside (in any text field - there are 4), when hitting enter it makes a new line without showing a <br> tag. Clicking outside and inside the textarea, it will show all the line breaks you've made.

 

My question is how to hide the <br> tag. What I've searched, found and tried the following:

 

 

$content=nl2br($content);
and
$content = str_replace("<br>", "\n", $content);

 

Neither worked.

 

Also when using this code

 

$file1 = include '/ccms/files/edit.txt';
echo $file1; // This outputs the file.

 

to show the content on another page, it adds a number 1 to every textarea I have on the original page. You can preview the number 1 error here.

 

 

Link to comment
Share on other sites

str_replace("<br>", "\n", $content);

 

Also doesn't work, it hides the <br>'s, but doesn't actually make one, its like doing a <br> and not going into the next line. (that line sort of disables <br>'s not only hiding them.)

Link to comment
Share on other sites

Also when using this code

 

$file1 = include '/ccms/files/edit.txt';
echo $file1; // This outputs the file.

 

to show the content on another page, it adds a number 1 to every textarea I have on the original page. You can preview the number 1 error here.

 

I found a fix to this, instead of

$file1 = include '/ccms/files/edit.txt';
echo $file1; // This outputs the file.

 

using

$file1 = include '/ccms/files/edit.txt';
$file1 = substr($file1, 0, -1);
echo $file1;

removes the "number 1" that becomes visible for no good reason at each textarea.

 

Or even better, using this below works without and errors.

$file1 = file_get_contents('/ccms/files/edit.txt');
echo $file1;

 

But still the hiding of <br> remains a mystery. What we've done till now is:

str_replace("<br>", "\n", $content);

- it does hide the <br> tag, but it makes it inactive.

Link to comment
Share on other sites

Yes if you want to read a file into a variable use file_get_contents(). include probably returns a bool so that's why you were getting a 1 as it successfully included the file. it is not meant for reading it into a variable.

 

For removing the <BR>

 

how does it make it in active?

 

You should be not be writing the BRs to your flat file. Just when you display the data use nl2br() and it should work fine. Write the textarea data to the flatfile which contains "\n"s then when you display just use nl2br.

Link to comment
Share on other sites

If I use the code you gave me, it hides the <br>'s successfully, but when I enter a new line in the textarea it just doesn't happen. Like it removes <br> completely, not just hides it.

 

I'm trying different variations, do you think the js library could be the problem, instead of php?

Link to comment
Share on other sites

It's a really simple thing, in a few steps:

 

It makes a textarea that is writable to a .txt file. I display this text area with:

<div id="change"><span id="a1" class="editText"><? echo $textInfile; ?></span></div>

.

 

This goes trough:

<?
$thefile = "files/edit.txt";
$textInfile = file_get_contents($thefile);
?>

This saves the file to edit.txt

 

The main config has these:

$fieldname = htmlspecialchars($_GET['fieldname']); 
$content = stripslashes(strip_tags($_GET['content'],"<p><img><i></i></p><h1></h1><h2></h2></a><li></li><a><strong><em><strike><b>"));
$content = trim($content);
$content=nl2br($content);

 

User enters content into the text area and it writes it directly to the txt file once the user clicks out of the area.

 

So far the most efficient thing that worked (or not) is :

str_replace("<br>", "\n", $content);

This would be perfect if it didn't disable <br>'s completely.

 

Also another thing, when you click on the text area on http://krneky.com/ccms (password demo) the text area shows normal <br> tags, while the ones saved in http://krneky.com/ccms/files/edit3.txt (the text files), shows <br />.

 

I have no idea what else is there to try.

 

Edit: I'm also using

 

- http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js

- http://krneky.com/ccms/js/editInplace.js

- http://krneky.com/ccms/js/wkrte.js

- http://krneky.com/ccms/js/jquery-1.3.2.min.js

 

Do you think any one of these may be causing problems?

Link to comment
Share on other sites

All fixed and ready for download, the problem was fixed by changing

 

function editBox(actual) {
if(!changing){
width = widthEl(actual.id) + 20;
height =heightEl(actual.id) + 2;
actual.innerHTML = "<textarea…"
changing = true;
}
actual.firstChild.focus();
}

 

to

 

function editBox(actual) {
if(!changing){
width = widthEl(actual.id) + 20;
height =heightEl(actual.id) + 2;
str = actual.innerHTML;
actual.innerHTML = str.replace(/<br>/gi, "");
actual.innerHTML = "<textarea…"
changing = true;
}
actual.firstChild.focus();
}

 

The WonderCMS is now available for download: WonderCMS

 

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.