Log in

View Full Version : How to make paragraph in my simple text editor



magictouch
06-04-2016, 08:32 PM
Hi, I created a small text editor for my website with my small knowledge. The problem is that each time I publish Something with it it does not show the new paragraph and puts all the text in the same paragraph. Someone can help me to make in a way that each time I press enter it makes a new paragraph? I only know php and a bit of javascript. I have no idea what I could do and what to search for it. Thanks. I'm a begginer so I need an simple language and explanation, I only know some php and javascript, slowly learning.
Here is the code I did:


<?php

mb_language('uni');
mb_internal_encoding('UTF-8');

if(isset($_POST['submit']))
{
if(!empty($_POST['titre'])&&!empty($_POST['message']))

{
$titre=$_POST['titre'];
$message=$_POST['message'];
$id=$_POST['id'];

$query=mysql_query("INSERT INTO editor(id,titre, message) VALUES
('$id','$titre','$message')");
if($query)
{$select=mysql_query("SELECT * FROM editor ORDER BY id DESC");

while($row=mysql_fetch_assoc($select))
{
echo $row['titre']."<br><strong>".$row['message']."</strong><br>";
}
}

}
} else echo "Vous devez saisir tout les champs pour pouvoir poster un commentaire";



?>

<form method='POST' action='index.php' enctype="multipart/form-data" name="myform">
<strong>Poster un texte</strong>
<p></p>
<p>titulo</p>
<textarea name="titre" rows="2" cols="35"></textarea><br>
<p>Texto</p>
<textarea name="message" style="display:none;" rows="6" cols="35"></textarea><br>





<br>


<input type="submit" name="submit" value="Poster"">
</form>



<?php
$getquery=mysql_query("SELECT * FROM editor ORDER BY id DESC");
$rows=mysql_fetch_assoc($getquery);
do {?>
<div id="a" style="border:2px solid #a1a1a1;
padding:3px 10px;
background:#f2d9f2;
width:260px;
border-radius:10px;
text-decoration:no;"
>


<a href="newsarticle.php?id=<?php echo $rows['id'];?>" target="new"><?php echo $rows['titre'];?></a><br>
<?php echo $rows['message'];?><br>
</div><br>
<?php } while($rows=mysql_fetch_assoc($getquery))


?>

Beverleyh
06-05-2016, 10:26 AM
A basic textarea cannot interpret new lines as new paragraphs, so it sounds like you need to use JavaScript to interpret the keystrokes and insert markup on the fly.

Try researching "JavaScript markup editor", "JavaScript WYSIWYG editor", "JavaScript rich text editor", and "JavaScript markdown editor". You'll find various plugins that you can test. Each behave differently and some are more feature-packed so it's up to you to decide what suits your needs best.

From a personal perspective, I prefer TinyMCE for my Fast Edit (http://fast-edit.co.uk/) and Fast Apps (http://fast-apps.co.uk/) freebies. They all use a WYSIWYG editor that can support HTML markup, from basic bold and lists to tables and image uploads, etc. You can customise TinyMCE any way you like, making it more advanced or really basic. I use version 3.x due to custom PHP mods, although they're now on v4, which is much more modern looking and adapts better to responsive admin panels. TinyMCE is also bundled with popular CMS packages such as Joomla! so it's easier for clients and the people I train/work with to move from one application to another, without feeling like they have to learn something new each time

magictouch
06-06-2016, 05:45 PM
hi, thanks for the answer. I know some of this editors, but a I dont have much knowledge I dont know always to use it. I created a wysiwyg file and it works well, the problem is I tried to store in the database and it did not work, so I have no idea how to do to put in the database the things I publish with my wysiwyg editor. Can you help me?
Thank you.

magictouch
06-06-2016, 06:12 PM
I tryed this code with a php query to insert in the database but did not work:

<html>
<head>
<script src="wysiwyg/wysiwyg.js"></script>
</head>
<body onLoad="iFrameOn();">
<h2>My web application that intakes data from users</h2>
<form action="my_parse_file.php" name="myform" id="myform" method="post">
<p>Entry Title: <input name="title" id="title" type="text" size="80" maxlength="80" /></p>
<p>Entry Body:<br>
<div id="wysiwyg_cp" style="padding:8px; width:700px;">
<input type="button" onClick="iBold()" value="B">
<input type="button" onClick="iUnderline()" value="U">
<input type="button" onClick="iItalic()" value="I">
<input type="button" onClick="iFontSize()" value="Text Size">
<input type="button" onClick="iForeColor()" value="Text Color">
<input type="button" onClick="iHorizontalRule()" value="HR">
<input type="button" onClick="iUnorderedList()" value="UL">
<input type="button" onClick="iOrderedList()" value="OL">
<input type="button" onClick="iLink()" value="Link">
<input type="button" onClick="iUnLink()" value="UnLink">
<input type="button" onClick="iImage()" value="Image">
</div>
<!-- Hide(but keep)your normal textarea and place in the iFrame replacement for it -->
<textarea style="display:none;" name="myTextArea" id="myTextArea" cols="100" rows="14"></textarea>
<iframe name="richTextField" id="richTextField" style="border:#000000 1px solid; width:700px; height:300px;"></iframe>
<!-- End replacing your normal textarea -->
</p>
<br /><br /><input name="myBtn" type="button" value="Submit Data" onClick="javascript:submit_form();"/>
</form>
</body>
</html>


my_parse_file.php

<?php
echo '<h2>You posted:</h2><hr />'. $_POST['title'] . '<hr />' . stripslashes($_POST['myTextArea']);
?>

rubyOnPails
11-26-2016, 02:06 AM
I know this doesn't necessarily solve your issue, but I personally believe that adding a Markdown editor might be your best option.