提交表单失败后,PHP保留表单信息
问题描述:
你好 我正在mvc系统视图中构建表单,并且我希望所有插入的值都将保留,以防表单提交失败. 如何做到这一点:我尝试过(一个字段的示例):
Hello I am building a form in a mvc system view, and i want that all the inserted values will be kept,in case of form submit failure. How can this be done: i tried like (example for a field):
<label for="user_firstname">Nume</label>
<input id="user_firstname" type="text" name="user_firstname" value=<?= $_POST['user_firstmane'] ?> >
<? if (isset($errors['user_firstname'])): ?>
<span class="error"><?= $errors['user_firstname']; ?></span>
<? endif; ?>
但是,当然,这在第一次(当未执行后期操作时)不起作用.
but of course, it doesn't work the first time (when no post action is done).
最简单的方法是什么?有什么想法吗?
what is the simplest way to do this? any ideas?
谢谢
答
我建议如下:
<label for="user_firstname">Nume</label>
<input id="user_firstname" type="text" name="user_firstname" value=<?(isset($_POST['user_firstname']) ? $_POST['user_firstname'] : ""; ?>>
<? if (isset($errors['user_firstname'])): ?>
<span class="error"><?= $errors['user_firstname']; ?></span>
<? endif; ?>
您在$ _POST ["user_firstmane"]中也有错字,应该是$ _POST ["user_firstname"]:)
You also had a typo in the $_POST["user_firstmane"] should be $_POST["user_firstname"] :)