Home  >  Article  >  Backend Development  >  21 PHP form validation - complete form example

21 PHP form validation - complete form example

WBOY
WBOYOriginal
2016-08-08 09:19:17873browse

PHP - Preserving values ​​from form

<code>如需在用户点击提交按钮后在输入字段中显示值,我们在以下输入字段的 value 属性中增加了一小段 PHP 脚本:name、email 以及 website。在 comment 文本框字段中,我们把脚本放到了 <textarea> 与 </textarea> 之间。这些脚本输出 <span>$name</span>、<span>$email</span>、<span>$website</span> 和 <span>$comment</span> 变量的值。</code>

Then we also need to show which radio button is selected. For this, we have to manipulate the checked attribute (not the value attribute of the radio button):

<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 form validation - complete form example

The above has introduced 21 PHP form validation-complete form examples, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP basic tutorial notesNext article:PHP basic tutorial notes