Why is iframe not being printed in the input?

Asked

Viewed 107 times

3

I’m putting the contents of an iframe in an input, only it does not appear complete, just this in the input text:

<iframe width=

And it appears on the bottom line:

" type="text"/>

Look at the code where I update the field "name" and "iframe", when it appears what is registered in iframe is giving problem, iframe does not appear all in the input:

<?php include("header.php"); ?>
<div id="box">
    <div id="header">
        <div id="header_logo">
            <a href="painel.php"><img src="../images/DCDesenvolvimento.png" alt="" border="0"/></a>
        </div>
    </div>
    <div id="content">
        <div id="menu">
            <?php include("menu.php");?>
        </div>

        <div id="conteudo">
            <span class="caminho">Home &raquo; Editar Vídeos</span>
            <h1>Cadastrar Post</h1>
<?php
            if(isset($_POST['cadastrar_post']) && ($_POST['cadastrar_post'] == "cad"))
            {
                $id_a_editar = strip_tags(trim($_POST['id_do_post']));
                $nome = strip_tags(trim($_POST['nome']));
                $iframe = $_POST['iframe'];
                $editar_posts = mysqli_query($conexao,"UPDATE baterista 
                                                            SET nome = '$nome', video = '$iframe'
                                                                WHERE id = '$id_a_editar'")or die(mysqli_error($conexao));
                if($editar_posts>=1)
                {
                    echo "<div class=\"ok\">Seu tópico foi atualizado com sucesso!</div>";
                }
                else
                {
                    echo "<div class=\"no\">Seu tópico não foi atualizado</div>";
                }
            }

            $editar_post_id = $_POST['id_do_post'];

            $dados = mysqli_query($conexao, "SELECT id, nome, video 
                                                FROM baterista WHERE id = '$editar_post_id'")or die(mysqli_error($conexao));
            if(mysqli_num_rows($dados) == 0)
            {
                echo "Não encontramos notícias nesse momento";
            }
            else
            {
                while($res_videos = mysqli_fetch_array($dados))
                {
                    $id_do_post = strip_tags(trim($res_videos[0]));
                    $nome = strip_tags(trim($res_videos[1]));
                    $iframe = $res_videos[2];
?>
            <form name="cadastrar_posts" method="post" action="" onsubmit="return valida()" enctype="multipart/form-data">
                <fieldset>
                                        <span>Nome</span>
                    <input name="nome" value="<?=$nome?>" id="nome" type="text"/>
                    <span id="avisonome"></span>
                    <span>Iframe</span>
                    <input name="iframe" value="<?php echo $iframe;?>" type="text"/>
                    <input type="hidden" name="cadastrar_post" value="cad"/>
                    <input type="submit" value="Editar" class="cadastro_btn" name="editar"/>
                </fieldset>
            </form>
<?php
                }
            }
?>
        </div>
    </div>
    <div id="clear"></div>
</div>
<?php include("footer.php");

1 answer

3


Is giving conflict with the double quotes of the string $iframe, which is an HTML code that has attributes using double quotes, with double quotes from value="". This is causing a break in the delimiter (double quotes) of the attribute value of input.

Your code is getting something like this:

<input name="iframe" value="<iframe width="100%"></iframe>" type="text"/>

See the quotes from the width conflict with the delimiting quotes of value.

You can solve this simply by changing the double quotes of value in single quotes:

<input name="iframe" value='<?php echo $iframe;?>' type="text"/>
                           ↑                     ↑

With this there will be the break of the delimiter value, being like this:

<input name="iframe" value='<iframe width="100%"></iframe>' type="text"/>

Or using the function htmlspecialchars:

<input name="iframe" value="<?php echo htmlspecialchars($iframe);?>" type="text"/>

Browser other questions tagged

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