Tag Form closes alone

Asked

Viewed 424 times

0

When I send this html code via ajax it displays correctly, but closes the Form tag right after opening it, is there another way to do this? or there is some syntax error.

$FormUserCad = '<div class="Ctn_Form_Cad">
        <div class="input_form_cad">
            <div>
                <div><form action="oi.php" method="post"></div>
                <div><label>Nome:<label></div>
                <div><input name="nome" type="text"></div>
            </div>
            <div>
                <div><label>Idade:<label></div>
                <div><input type="text"></div>
            </div>
        </div>  
        <div class="input_form_cad">
            <div>
                <div><label>Rua:<label></div>
                <div><input type="text"></div>
            </div>...
</form> <--



$retorno = array('codigo' => 0, 'mensagem' => $FormUserCad);
            echo json_encode($retorno);
            exit();
  • But if you open one form, it has to be closed even by logic, otherwise your form will not work. I don’t understand your doubt.

  • it closes itself, example <form action="hi"></form> not at the end of the code as desired, and it removes the </form> from the end of the code

  • 1

    Every HTML element that opens will be closed by the browser, regardless of whether you closed correctly or not, the browser constructs a terminal from the last closed element correctly. And yes, it is a syntax error to leave your html tag open. Even it also takes the freedom to move your place element, as for example if you put a src script, below the browser, outside the body, it will fix by placing it inside the body.

1 answer

2


Adjust your html to the correct form of the html structure. And then try using htmlspecialchars

$FormUserCad = '<div class="Ctn_Form_Cad">
       <form action="oi.php" method="post">
        <div>
            <div><label>Nome:<label></div>
            <div><input name="nome" type="text"></div>
        </div>
        <div>
            <div><label>Idade:<label></div>
            <div><input type="text"></div>
        </div>
        <div>
            <div><label>Rua:<label></div>
            <div><input type="text"></div>
        </div>

        ...

       </form>
   </div>';

    $retorno = array('codigo' => 0, 'mensagem' => htmlspecialchars($FormUserCad,ENT_QUOTES));
    echo json_encode($retorno);
    exit();

Browser other questions tagged

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