Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

mmillers

edição de texto com jquery

Recommended Posts

Saudações pessoal,

 

estou com um problema na minha edição de texto. Tenho dois arquivos "home.php" e "att.php" para edição e atualização de texto, eles funcionam porém me deparei com um problema quando eu dou "enter" ou seja, inicio um novo parágrafo não é salvo como parágrafo e sim como continuação após o ponto final. Segue abaixo o código.

 

página home.php com script

<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script>
    $(document).ready(function(){    
        $('#save').hide();
        $('#cancel').hide();
        $('#editPanel').click(function() {  
            $('#editPanel').attr('contentEditable', true);
            $('#editPanel').focus();
            $('#editPanel').css('cursor','text');
            $('#save').fadeIn();
            $('#cancel').fadeIn();
        });
        $('#save').click(function(){    
            var text = $('#editPanel').html();
            //alert(text);
            $("#Mesg").html('<img  src="load.gif" id="loader" />');
             $.ajax({
                type: "POST",
                url: "att.php?text=" + text,
                success: function(){
                 $("#Mesg").html('Text Updated !');
                 $('#editPanel').attr('contentEditable', false);
                 $('#editPanel').css('cursor','pointer');
                 $('#save').fadeOut();
                 $('#cancel').fadeOut();
                }
             });
         });
         $('#cancel').click(function(){    
             $('#editPanel').attr('contentEditable', false);
             $('#editPanel').css('cursor','pointer');
             $('#save').fadeOut();
             $('#cancel').fadeOut();
         });
    });
</script>
</head>
<body>
       <div>
            <?php include_once('att.php');?>
            <a href="#" id="save" class="save">Save</a>
            <a href="#" id="cancel" class="cancel">Cancel</a>
      </div>
</body>
</html>

 

Página att.php (estou passando ID na sql para testes)

	<?php
	include('dbcon.php'); // faz a conexão e seleção do banco
	function checkValues($value){
		$value = trim($value);
		if (get_magic_quotes_gpc()) {
			$value = stripslashes($value);
		}
		$value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));
		$value = strip_tags($value);
		$value = mysql_real_escape_string($value);
		$value = htmlspecialchars ($value);
		return $value;
	}	
	if($_REQUEST['text']){
		$text = checkValues($_REQUEST['text']);
		mysql_query("update edit_able set text = '".$text."' where id = 1");
		$result = mysql_query("SELECT * from edit_able where id = 1");
	}
	else {
		$result = mysql_query("SELECT * from edit_able where id = 1");
	}
	while ($row = mysql_fetch_array($result))
	{?>
		<p id="editPanel">
		<?php
		echo $row['text'];?>
		</p>
		<?php
	}?>

 

Desde já obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Boa tarde Caio,

 

Salvei o texto com \n para testar e coloquei a função que me indicou desta forma no código:

while ($row = mysql_fetch_array($result)){
$vart =  $row['text'];
?>
		<p id="editPanel">
		<?php
		echo nl2br($vart);?>
		</p>
		<?php
	}?>

neste lugar é onde faz a leitura porém nada acontece.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.