首頁  >  文章  >  後端開發  >  21 PHP 表單驗證 - 完成表單實例

21 PHP 表單驗證 - 完成表單實例

WBOY
WBOY原創
2016-08-08 09:19:17907瀏覽

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 表單驗證 - 完成表單實例

以上就介紹了21 PHP 表單驗證 - 完成表單實例,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn