Población indirecta de Textarea en formulario HTML usando PHP

I am working on an "Update User Data" form, which should reflect the initially entered information stored in the database into the textarea, and can be changed if the user wishes to. While I'm doing so, I have a concern - is directly writing value = <?php //some code ?> the safest bet?

I was trying to invoke a function to place my PHP code in that instead, but apparently it's just displaying the function's name.

Aquí está mi fragmento de código:

<div>Date of Birth: </div>
    <input id="dob" type="date" onFocus="emptyElement('status')" value="reflect_data('dob');">

where the function reflect_data is defined as -

function reflect_data(elem) {
//query and some code to access the data and store into $member

if (elem == "dob") {
    echo $member['DOB'];
    exit();
}

NOTE : A newbie to PHP, any advice would be welcome. Thanks. :)

preguntado el 12 de junio de 14 a las 10:06

Once the browser receives the web page, php has long forgotten about the page that you are seeing. value = <?php //some code ?> is about the only way to show data immediately unless you want to go the Ajax route. -

Oh, Okay. Thanks for the technical explanation, @jeff, makes sense now. :) -

1 Respuestas

You use php code in a JS function. That won't work that way and is impractical. Simple:

<input id="dob" type="date" onFocus="emptyElement('status')" value="<?php echo htmlspecialchars($member['DOB']); ?>">

es la mejor solución

Respondido el 12 de junio de 14 a las 10:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.