【发布时间】:2021-06-29 12:32:59
【问题描述】:
场景: 我在 PHP 标记中有这个简单的 HTML 5 表单。
<?php
echo '
<form method="post" action="index.php">
<input type="email" name="email value="<?php echo $email; ?>">
<input type="password" name="password">
<button type="submit" name="signin">Sign in</button>
</form>
';
?>
表单显示正确,但我无法获取 $email 的值,它只是显示为原始文本。
那么,如何从 PHP 标记内的表单中回显 php 变量。
最终代码
<?php
echo '<form method="post" action="index.php" class="navbar-form navbar-right">
<input type="email" name="email" placeholder="Email" class="form-control1" value="' . $email . '">
<input type="password" name="password" placeholder="Password" class="form-control">
<button type="submit" name="signin">Sign in</button>
</form>';
?>
【问题讨论】:
-
在 name 和 value 属性之间放一个空格,你会回显到回显中。我认为这行不通,只需将 html 字符串放在 php 结束标记之后