Because input does not appear in php Function output

Asked

Viewed 210 times

0

I created a function (I’m doing some experiments) to generate input, textarea, select, etc, through Function. But the result is partial. There is no error in the function, but only what is text (without being in the input) appears and the input is shown in the source code, but in the same page, nothing comes.

Code:

    // type (textarea ou o type do input) | name | id | required (required ou vazio) | placeholder | Titulo que vem antes do input | conteudo é o echo do BD (pode ser um array quando para select | onlyread (onlyread ou vazio) | checked ou selected ou vazio | options (array com opções para select ou opções para radio e check | primeira serve para primeira opção em selects

function geraInput($type, $name, $id, $required, $place, $titulo, $conteudo, $onlyread, $checked, $options, $primeira){

$inp = '<div class="env_inputs">
        <span class="tit_inputs">'.$titulo.'</span>
    <input type="'.$type.'" name="'.$name.'" id="'.$id.'" '.$required.' '.$place.' value="'.$conteudo.'" '.$onlyread.'></div>';

return $inp;
}

In the function call:

echo geraInput("text", "teste1", "teste", "", "", "Teste:", $resumo, "", "", "", "");

In the source code:

<div class="env_inputs">
    <span class="tit_inputs">Teste:</span>
    <input type="text" name="teste1" id="teste"   value="<p>Casa nova, com 2 dormitorios, banheiro, sala de jantar e estar, 2 vagas de garagem, cozinha, &aacute;rea de servi&ccedil;o, churrasqueira.&nbsp;</p>
<p>Pronta para finaciar e morar !!</p>">
</div>

Onscreen:

Teste:
  • Its variable $conteúdo has html element <p><\p> and so tah bugging his element <input>

  • So, thanks for the answer, first. I put a strip_tags on the variable that fills the value and did not change the result on the screen. In the source code the <p> disappeared, but did not change the result on screen.

  • 1

    Tried different browsers? I tested here on Chrome 49 and functioned normal, including the html you posted.

  • 1

    Which browser are you using to test? Which doctype is defined in HTML? What is the content of css env_inputs? There is some other css style for elements <input> ?

  • Putz! Cara, thanks. The problem was not in the code. It was a div with id test that was in another include and had a css with diplay None. It was my fault. Sorry and thanks for the help.

1 answer

1


Try the function like this:

function geraInput($type, $name, $id, $required, $place, $titulo, $conteudo, $onlyread, $checked, $options, $primeira){

$inp = '<div class="env_inputs">
        <span class="tit_inputs">'.$titulo.'</span>
    <input type="'.$type.'" name="'.$name.'" id="'.$id.'" '.$required.' '.$place.' value="'.htmlentities($conteudo).'" '.$onlyread.'></div>';

return $inp;
}

I added html_encode()to prevent value elements from bouncing input. Test and pass feedback!

  • It didn’t work buddy. This function gives error - I didn’t find documentation in the php manual. I tried with htmlentities, htmlspecialchars... Nothing makes the input appear on the screen...

  • Sorry, my mistake! would be the same 'htmlentities', but your problem really isn’t that! I tested here on passed normal your code.

Browser other questions tagged

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