I'm working on a CMS that does text editing already in the database, it works as follows: there is a series of inputs[type="radio"]
each one of them is a project, and when one of them is clicked appear 4 textareas
(via Ajax) with the four texts corresponding to this project. My problem is that in the texts the </ br>
entered previously with the nl2br
function of PHP, this is a problem because who will edit the texts do not need to see this. I have the following code:
editForm.php:
if(isset($_POST['editTexts'])) {
if (!empty($_POST['projectIdToEditTexts'])) {
$id = $_POST['projectIdToEditTexts'];
$textSeveralToEdit = nl2br(trim(htmlentities(ucfirst($_POST['editTextSeveral']))));
$extraTextToEdit = nl2br(trim(htmlentities(ucfirst($_POST['editExtraTextSeveral']))));
$textSeveralPTToEdit = nl2br(trim(htmlentities(ucfirst($_POST['editTextSeveralPT']))));
$extraTextPTToEdit = nl2br(trim(htmlentities(ucfirst($_POST['editExtraTextSeveralPT']))));
$dataBase->updateTextsEdit($id, $textSeveralToEdit, $extraTextToEdit, $textSeveralPTToEdit, $extraTextPTToEdit);
echo '<p style="text-align:center; color:green;">Success!!<br><br>Text updated!!</p>';
}
else {
echo '<p style="color:red; text-align:center">You must choose a project where to edit the Texts!!</p>';
}
}
?>
<form action="" method="POST">
<h2>Edit texts from project</h2>
Select the project you want to edit:
<br>
<?php
foreach ($dataBase->fetchAllProjectsAdmin() as $EditButton) {
?>
<input class="radioEditTexts" type="radio" name="projectIdToEditTexts" value="<?php echo $EditButton->id; ?>">
<?php
echo '<h4>' .$EditButton->description. '</h4>';
} ?>
<br>
<div id="editTexts">
</div>
<br>
<input type="submit" name="editTexts">
</form>
......
$('.radioEditTexts').click(function() {
var viewTexts = $(this).attr('value');
$.ajax({
type: 'GET',
url: '../Ajax/editTexts.php',
data: {"idProject":viewTexts},
success: function(data) {
$('#editTexts').stop().html(data).hide().fadeIn(500);
}
});
});
editTexts.php
$projectId = $_GET['idProject'];
$getTexts = $dataBase->getDetailsById($projectId)[0];
$mainTextEN = $getTexts->text_several;
$extraTextEN = $getTexts->extra_text;
$mainTextPT = $getTexts->text_severalPT;
$extraTextPT = $getTexts->extra_textPT;
?>
<label>Main Text (PT)?<br><br>
<textarea name="editTextSeveralPT" cols="50" rows="5"><?php echo $mainTextPT; ?></textarea>
</label>
<br>
<br>
<label>Extra text (PT)?<br><br>
<textarea name="editExtraTextSeveralPT" cols="50" rows="5"><?php echo $extraTextPT; ?></textarea>
</label>
<br>
<br>
<label>Main Text?<br><br>
<textarea name="editTextSeveral" cols="50" rows="5"><?php echo $mainTextEN; ?></textarea>
</label>
<br>
<br>
<label>Extra text?<br><br>
<textarea name="editExtraTextSeveral" cols="50" rows="5"><?php echo $extraTextEN; ?></textarea>
</label>