I want to know if there is any way I can save two values in the same session variable as if it were an array, since I want to save both the input text value and the wysiwyg element by clicking the "save chapter" button in the image. , I tried to do it like this:
<?php
session_start();
$titulo = isset($_POST['titulo']) ? $_POST['titulo'] : '';
$paragrafo = isset($_POST['valor_paragrafo']) ? $_POST['valor_paragrafo'] : '';
$p = $_GET['p'];
$_SESSION[$p][0] = $titulo; //aqui salvaria os valores na session
$_SESSION[$p][1] = $paragrafo;
?>
Only when I display on the screen, if I save that way, on the screen at the time I'm going to display, only the index letter appears that I put in the session instead of the whole text. code to display the values on the screen:
$(document).ready(function() {
$("#paragrafo").Editor();
$('#paragrafo').Editor('setText', '<?=addslashes($_SESSION["$p"][1])?>');
$('#titulo').val('<?=($_SESSION["$p"][0])?>');
});
The first php code posts arrive from this html and javascript:
function Envia_Form(valor, arquivo, chooser, target){ //valor do chooser: 0 = faz submit com refresh na pagina | 1 = sem refresh na pagina
$("#valor_paragrafo").val(valor);
if(chooser == 0){
$("#form").attr("action",arquivo);
if(target != ''){
$("#form").prop("target", target);
}
document.form.submit();
} else if(chooser == 1){
$.post(
arquivo,
$('#form').serialize(),
function( data ){
}
);
}
}
<form id="form" name="form" method="post" action="proc.php">
<div class="titulo">TÍTULO
<input type="text" class="titulo-input" name="titulo" id="titulo" placeholder="Digite o texto">
</div>
<div class="container-fluid">
<div class="row">
<div id="paragrafo" name="paragrafo"></div>
<input type="hidden" id="valor_paragrafo" name="valor_paragrafo" />
</div>
<p>
<br>
<input type="button" value="Salvar Capítulo" onclick="Envia_Form($('#paragrafo').Editor('getText'), 'salva_paragrafo.php?p=<?=$p?>', 1);" />
<input type="button" value="Gerar PDF" onclick="Envia_Form($('#paragrafo').Editor('getText'), 'proc.php', 0, '_blank');" />
</p>