Jump to content

Recommended Posts

Okay I am using Ajax to edit the About information in place over the admin panel...  so when I put it in, it has multiple new lines...  When I use nl2br() on it for the display reasons, it works perfect, however -- when i click on the text to edit, it has all the html <BR> in the text box and that is annoying me...

 

Any clue what I should do here? if ya need code let me know.

Link to comment
https://forums.phpfreaks.com/topic/52239-new-line-br-question/
Share on other sites

I didn't store that text, see here is my code...

<?php
switch ($action) {
case about:
		// edit is in edit.php
	$page = "about";
	switch($act) {
		default:
		$data = mysql_result(mysql_query("SELECT * FROM about"), 0);
		$data = nl2br($data);
		$turbo->assign('data', $data);
		break;
	}
break;
}
?>

 

that is in my index.php...

 

and here is my about.tpl with javascript in it...

 

<link href="../styles.css" rel="stylesheet" type="text/css" />
<script src="../includes/mainframe.js" type="text/javascript"></script>
{literal}
<script language="javascript">
Event.observe(window, 'load', init, false);

function init(){
makeEditable('desc');
}

function makeEditable(id){
Event.observe(id, 'click', function(){edit($(id))}, false);
Event.observe(id, 'mouseover', function(){showAsEditable($(id))}, false);
Event.observe(id, 'mouseout', function(){showAsEditable($(id), true)}, false);
}

function edit(obj){
Element.hide(obj);

var textarea = '<div id="'+obj.id+'_editor"><textarea id="'+obj.id+'_edit" name="'+obj.id+'" rows="20" cols="110">'+obj.innerHTML+'</textarea>';
var button	 = '<div><input id="'+obj.id+'_save" type="button" value="SAVE" class="formButtonBlue"/> OR <input class="formButtonR" id="'+obj.id+'_cancel" type="button" value="CANCEL" /></div></div>';

new Insertion.After(obj, textarea+button);	

Event.observe(obj.id+'_save', 'click', function(){saveChanges(obj)}, false);
Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}, false);

}

function showAsEditable(obj, clear){
if (!clear){
	Element.addClassName(obj, 'editable');
}else{
	Element.removeClassName(obj, 'editable');
}
}

function saveChanges(obj){

var new_content	=  escape($F(obj.id+'_edit'));

obj.innerHTML	= "Saving...";
cleanUp(obj, true);

var success	= function(t){editComplete(t, obj);}
var failure	= function(t){editFailed(t, obj);}

  	var url = 'edit.php?act=about';
var pars = 'id='+obj.id+'&content='+new_content;
var myAjax = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});

}

function cleanUp(obj, keepEditable){
Element.remove(obj.id+'_editor');
Element.show(obj);
if (!keepEditable) showAsEditable(obj, true);
}

function editComplete(t, obj){
obj.innerHTML	= t.responseText;
showAsEditable(obj, true);
}

function editFailed(t, obj){
obj.innerHTML	= 'Sorry, the update failed.';
cleanUp(obj);
}
</script>
{/literal}
<p><span class="pgHdr">About Us :</span></p>
<p class="bodytextSmallBlue" id="desc">{$data}</p>

 

See the javascript takes the obj.innerHTML which is the text and it turns to be the text that has had nl2br run on it... 

 

if i edit them out, and save it doesnt save it into the database with <br> just the invisible new lines...

Link to comment
https://forums.phpfreaks.com/topic/52239-new-line-br-question/#findComment-257738
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.