Take all content from a div and write at the beginning of a file

Asked

Viewed 224 times

0

I’m making a posting creation system, in which the user, before saving the post, can view it. The visualization works perfectly, capturing the input values of the editing 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>

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 the posts.php? You can use the $_REQUEST or $_POST array using the name attribute of the submitted form as Indice:

    echo $_REQUEST['tipo'];
    echo $_REQUEST['cor'];
    echo $_REQUEST['titulo'];
    echo $_REQUEST['subtitulo'];
    echo $_REQUEST['conteudo'];
  • 1

    And how to write the post with the values at the beginning of posts.php?

  • Good morning @Daniel, if my suggestion helped you, I could mark it as an answer?

  • Thank you @Danielbonifácio

0

If that’s what I’m thinking according to your words, you can try creating a form with a textarea, and the editor will put the text there! And by clicking the Preview button (for example), you can send this data from the textarea and title etc, via post pro methods posts.php!

On the page posts.php you can build a design according to your dashboard there, and can put several types of posts, such as the post title, the description, information know!

Just create a form, and on the preview button, redirect to.php posts 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.php posts:

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

To write this data:

    echo ($titulo);
    echo ($texto);
// e por aí vai

0

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

But I believe it will be solved like this

You will save in a variable the ready HTML, put in a input type="hidden" and send 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 his posts.php you would do so

<?php 
    echo $_POST['posts'];
 ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.