服务器验证发生之前,数据需要自动存储在html元素中 [英] data needs to be stored in html elements automatically before server validation occurs
问题描述
我只是有一个疑问:
我有一个在其中进行服务器端验证的表格..我具有验证的np,但概率是:
在一个表单中,假设我输入了大约9个字段(而不是10个),它向我显示了一个错误,说缺少第10个字段",我必须重新输入在9个字段中输入的所有数据.有时由于小错误,很难重新输入相同的数据)
因此,我们的目标是认为无论先前在textfield或textarea或其他html元素中输入的数据是什么,即使在服务器验证后也应自动保存.
我怎么能做到这一点.我在google上尝试过,但不了解如何搜索这种情景,我还没有找到任何解决方案.
很抱歉我的英语不好..希望你能理解我的问题.
那么,有什么建议吗??
@Jim,情况与
因此,不必每次都发回以下内容... 您需要发回最初在控件中输入的内容... 使用复选框和收音机(这是您最初的问题),您需要类似... 在谈论
更新 在将HTML构建到 如果您在构建字符串的过程中 执行了 因此,对于单行文本框,您可以... 对于复选框,您可以... 对于多行文本框,您可以...... 因此,您看到我们将控件的现有值包含在要构建的字符串中. I just had one doubt: I have a form where I do server side validation.. i have np with validation, BUT the prob is: In a Form, assume I entered some 9 fields (instead of 10 ), it shows me an erros saying that '10th field missing' and all the data I entered in 9 fields has to be re-entered again.. (sometimes its really damn tough to re-enter same data because of small mistake ) so, aim thinking that whatever the data entered previously in textfield or textarea or some other html element, it should be saved automatically even after server validation does.. so that user need not re-type again.. how can I achive this.. I tried in google, but didnt understood how to search for this kind of sittuation and i did not find any solution yet.. sory for my bad english.. Hope u udnerstood my prob.. so, any suggestions..? @Jim, this is the same situation as in your original question. PHP will not keep the "state" of the control when you send it back to the browser after a post-back. So instead of sending back the following each and every time... You need to send back what was originally entered as part of the control... With checkboxes and radios (which was your original question), you need something like... And as you're talking about
Update As you are building the HTML into the If you do an So, for a single line textbox you would do... For a checkbox you would do... For a multi line textbox you would do.... So you see that we are including the existing value of the control as part of the string that you are building. 这篇关于服务器验证发生之前,数据需要自动存储在html元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<input type="text" id="mytext" name="mytext">
<input type="text" id="mytext" name="mytext"
value="<?php echo $_POST['mytext']; ?>>
<input type="checkbox" id="mycheck" name="mycheck"
value="<?php echo (isset($_POST['mycheck']) ? "checked" : ""); ?>>
<textarea>
控件时,您会做类似... <textarea id="mytext" name="mytext"><?php echo $_POST['mytext']; ?></textarea>
$echo
字符串变量中(而不只是直接标记HTML)时,您需要在字符串中包含上述代码 . >
echo
命令,则被echo
修饰的内容将立即发送到屏幕.然后,当您通过命令echo $echo;
发送$echo
的内容时,您将获得所有其他内容.$echo = '<input type="text" id="mytext" name="mytext" value="'. $_POST['mytext'] .'">';
$echo = '<input type="checkbox" id="mycheck" name="mycheck" '. (isset($_POST['mycheck']) ? "checked" : "") .'>';
$echo = '<textarea id="mytext" name="mytext">'. $_POST['mytext'] . '</textarea>';
(Before anybody points out that it is a different account, it's the same actual person - long story!)<input type="text" id="mytext" name="mytext">
<input type="text" id="mytext" name="mytext"
value="<?php echo $_POST['mytext']; ?>>
<input type="checkbox" id="mycheck" name="mycheck"
value="<?php echo (isset($_POST['mycheck']) ? "checked" : ""); ?>>
<textarea>
controls, you'd do something like...<textarea id="mytext" name="mytext"><?php echo $_POST['mytext']; ?></textarea>
$echo
string variable (rather than just having the HTML mark up directly), you need to include the above code as part of the string.echo
command during the building of the string, the thing being echo
ed will be sent to the screen straight away. Then when you send the contents of $echo
via the command echo $echo;
you get everything else.$echo = '<input type="text" id="mytext" name="mytext" value="'. $_POST['mytext'] .'">';
$echo = '<input type="checkbox" id="mycheck" name="mycheck" '. (isset($_POST['mycheck']) ? "checked" : "") .'>';
$echo = '<textarea id="mytext" name="mytext">'. $_POST['mytext'] . '</textarea>';