简体   繁体   中英

Indirect Population of Textarea in HTML Form Using 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.

Here's my code snippet:

<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. :)

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']); ?>">

is the best solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM