提交表单失败后,PHP保留表单信息 [英] PHP keep form info after submit form failed
本文介绍了提交表单失败后,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"] :)
这篇关于提交表单失败后,PHP保留表单信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文