Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP Complete Form Example

PHP Complete Form Example


This section will introduce how to ensure all fields are correctly entered before the user submits data by clicking the "Submit" button.


PHP - Ensuring Input Values in Forms

After the user clicks the submit button, to ensure the field values are entered correctly, we insert a PHP script into the HTML input elements, with field names: name, email, and website. For the textarea field in the comment, we place the script between the tags.

The PHP script outputs the values of: $name, $email, $website, and $comment variables. 

Then, we also need to check the selected radio button; for this, we must set up the checked attribute (not the value attribute of the radio button):



"> 名字: *

E-mail: *

网址:

备注:

性别: value="female">女 value="male">男 *


PHP - Complete Form Example

Below is the complete PHP form validation example code:

Example

Run Example »

The execution result of the example is similar to the figure shown below: