radar Posted May 20, 2007 Share Posted May 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52239-new-line-br-question/ Share on other sites More sharing options...
hitman6003 Posted May 20, 2007 Share Posted May 20, 2007 don't store the text with the nl2br function applied to it. Apply the nl2br just before displaying back the text. Quote Link to comment https://forums.phpfreaks.com/topic/52239-new-line-br-question/#findComment-257737 Share on other sites More sharing options...
radar Posted May 20, 2007 Author Share Posted May 20, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/52239-new-line-br-question/#findComment-257738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.