Get all contents of a div and write at the beginning of a file

0

I'm doing a posting system, in which the user, before saving the post, can view it. The view works perfectly, capturing the input values of the edit page. Now how do I get the contents of the div .post and play at the beginning of my posts.php , when the user clicks the save button.

        <div class="posts">
            <?php
                echo "<div class='post $tipo $cor'>
                <div class='post-title'>
                    <h2>$titulo</h2>
                </div>                               
                <div class='post-subtitle'>
                    <h3>$subtitulo</h3>
                </div>
                <div class='post-content'>
                    $conteudo
                </div>"
            ?>
          </div>
    
asked by anonymous 23.09.2016 / 21:38

3 answers

1

I would use a form with the data in a hidden field:

    <form action='posts.php' method="post">
        <input type='hidden' name='tipo' value='<?=$tipo?>' />
        <input type='hidden' name='cor' value='<?=$cor ?>' />
        <input type='hidden' name='titulo' value='<?=$titulo?>' />
        <input type='hidden' name='subtitulo' value='<?=$subtitulo?>' />
        <input type='hidden' name='conteudo' value='<?=$conteudo?>' />
        <input type='submit' value="Salvar" />
    </form>

And how to write the post with the values at the beginning of posts.php? You can use the $ _REQUEST or $ _POST array, using the 'name' attribute of the submitted form as an index:

    echo $_REQUEST['tipo'];
    echo $_REQUEST['cor'];
    echo $_REQUEST['titulo'];
    echo $_REQUEST['subtitulo'];
    echo $_REQUEST['conteudo'];
    
23.09.2016 / 22:13
0

Friend, I confess that I did not clearly understand what you are trying to do.

But I think it works out like this

You will save the HTML in a variable, put it in a input type="hidden" and send it via post to the page posts.php

<div class="posts">
    <?php
        $var = "<div class='post $tipo $cor'>
        <div class='post-title'>
            <h2>$titulo</h2>
        </div>                               
        <div class='post-subtitle'>
            <h3>$subtitulo</h3>
        </div>
        <div class='post-content'>
            $conteudo
        </div>";
    ?>
    <form action="posts.php">
        <input type="hidden" value="<?=$var?>" id="posts" name="posts">
        <input type="submit" value="enviar">
    </form>
</div>

There in your posts.php would you do so

<?php 
    echo $_POST['posts'];
 ?>
    
23.09.2016 / 22:39
0

If that's what I'm thinking about according to your words, you can try to create a form with a textarea, and the editor will put the text there! And when you click on the Preview button (for example), you can send this textarea and title data etc., through post pro methods.php!

In the posts.php page you can build a design according to your panel there, and can put various types of posts, such as post title, description, information knows!

Just create a form, and the preview button, redirects to posts.php where it shows all the necessary information, and then the editor can come back and the data will still be there! (Possibly).

An example of posts.php:

    $titulo = $_POST['titulo'];
    $texto = $_POST['texto'];
//e por aí vai

To write this data:

    echo ($titulo);
    echo ($texto);
// e por aí vai
    
23.09.2016 / 22:38