Php basic tutorial-2 create templates, process forms, basic tutorial forms

Source: Internet
Author: User

Php basic tutorial-2 create templates, process forms, basic tutorial forms

1. Create a template:

Copy the frequently-seen part of the page to an html or PHP file, and introduce it using the require ()/include () function in the original page.

Example:

Source html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

Copied header: header.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

Copy tail: footer.html:

<div><p>This is the foot of the document</p></div></body> 

Merging template: ws. php

<?phprequire('header.html');?><form action="handle.php" method="post"> <p> Name:<select name="title"> <option value="Mr">Mr</option> </select> <input type="text" name="name" size="20"/></p> <input type="submit" value="send"></form><?phprequire('footer.html');?>


2. process forms-display and process forms on a page at the same time

Conditional statement:

If (Form submission) {Processing Form}

Else {display form}


Example: Simple user name-password verification


Enter: User name: YF password: 123456

Display: Login successful

Cut chart:




Code: ws.php (header.html?footer.html references the template above ):

<?phpdefine('TITLE', 'Login');require('header.html');if (isset($_POST['submitted'])) {if ((!empty($_POST['name'])) && (!empty($_POST['password']))){if ((strtolower($_POST['name']) == 'yf') && ($_POST['password'] == '123456')){// name and password are correct.print '<p> logged in !</p>';}else {print '<p> name or password is worry!</p>';}}else {print '<p> make sure you enter both name and password!</p>';}}else {print '<form action="ws.php" method="post">  <p> Name:<input type="text" name="name"  size="20"/></p>  <p>Password:<input type="password" name="password" "size="20" /></p> <input type="submit" value="send"> <input type="hidden" name="submitted" value="true"/></form>';}require('footer.html');?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.