通过 PHP 按 id 预填充表单输入,但不在表单的 HTML 内使用 echo
Prefill form inputs by id via PHP but without using echo inside the HTML of the form
我需要在页面上预填表单输入,但我无法在表单的 HTML 内使用 echo。所有输入都有唯一的 ID,到目前为止我有这个代码。顺便说一下,这是 Joomla CMS 中的一个页面。
$user_id = $_GET['findId'];
$user = \JFactory::getUser($user_id);
echo $user->email;
上面的 echo 只是为了查看代码是否真的有效。
我一直在搜索 SO 和 Google 以获得答案,但我一直在寻找这些答案:
<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?>');
我需要在页面上预填表单输入,但我无法在表单的 HTML 内使用 echo。所有输入都有唯一的 ID,到目前为止我有这个代码。顺便说一下,这是 Joomla CMS 中的一个页面。
$user_id = $_GET['findId'];
$user = \JFactory::getUser($user_id);
echo $user->email;
上面的 echo 只是为了查看代码是否真的有效。
我一直在搜索 SO 和 Google 以获得答案,但我一直在寻找这些答案:
<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?>');