通过PHP通过id预填充表单输入,但不在表单的HTML中使用echo



我需要在页面上预先填充表单输入,但我不能在表单的HTML中使用echo。所有输入都有唯一的ID,到目前为止我有这段代码。顺便说一下,这是Joomla CMS内部的一个页面。

$user_id = $_GET['findId'];
$user = JFactory::getUser($user_id);
echo $user->email;

上面的回声只是为了看看代码是否真的在工作。

我一直在搜索SO和谷歌以获得答案,但我一直在寻找这些答案:

<input type="text" id="hello" name="hello" value="<?php echo $hello; ?>">

如何在不使用HTML中的echo语句的情况下实现相同的功能?

我应该在下面的代码中更改什么来实现这一点:

$user_id = $_GET['findId'];
$user = JFactory::getUser($user_id);
$hello.value = $user->email;

这可能是一个解决方案吗?

HTML

<input type="text" id="hello" name="hello">

JS

var inputfield = document.getElementById("hello");
inputfield.setAttribute('value', '<?=$hello?>');

最新更新