Rumah > Artikel > pembangunan bahagian belakang > 21 PHP 表单验证 - 完成表单实例
PHP - 保留表单中的值
<code>如需在用户点击提交按钮后在输入字段中显示值,我们在以下输入字段的 value 属性中增加了一小段 PHP 脚本:name、email 以及 website。在 comment 文本框字段中,我们把脚本放到了 <textarea> 与 </textarea> 之间。这些脚本输出 <span>$name</span>、<span>$email</span>、<span>$website</span> 和 <span>$comment</span> 变量的值。</code>
然后,我们还需要显示选中了哪个单选按钮。对此,我们必须操作 checked 属性(而非单选按钮的 value 属性):
<code>Name: <span>input</span><span>type</span>=<span>"text"</span><span>name</span>=<span>"name"</span><span>value</span>=<span>"<?php echo $name;?>"</span>>E-mail: <span>input</span><span>type</span>=<span>"text"</span><span>name</span>=<span>"email"</span><span>value</span>=<span>"<?php echo $email;?>"</span>>Website: <span>input</span><span>type</span>=<span>"text"</span><span>name</span>=<span>"website"</span><span>value</span>=<span>"<?php echo $website;?>"</span>>Comment: <span>textarea</span><span>name</span>=<span>"comment"</span><span>rows</span>=<span>"5"</span><span>cols</span>=<span>"40"</span>><span><span><?php </span><span>echo</span><span>$comment</span>;<span>?></span></span><span><span>textarea</span>></span>Gender: <span>input</span><span>type</span>=<span>"radio"</span><span>name</span>=<span>"gender"</span><span><span><?php </span><span>if</span> (<span>isset</span>(<span>$gender</span>) && <span>$gender</span>==<span>"female"</span>) <span>echo</span><span>"checked"</span>;<span>?></span></span><span>value</span>=<span>"female"</span>></span>Female <span>input</span><span>type</span>=<span>"radio"</span><span>name</span>=<span>"gender"</span><span><span><?php </span><span>if</span> (<span>isset</span>(<span>$gender</span>) && <span>$gender</span>==<span>"male"</span>) <span>echo</span><span>"checked"</span>;<span>?></span></span><span>value</span>=<span>"male"</span>></span>Male</span></code>
以上就介绍了21 PHP 表单验证 - 完成表单实例,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。