PHP Basic Tutorial--2 Creating templates, working with forms

Source: Internet
Author: User

One. Create a template:

Copy the frequently occurring parts of the page into an HTML or PHP file, which is introduced in the original page with the Require ()/include () function.

Example:

SOURCE HTML:


Copy of the head: header.html:


Tail of copy: footer.html:


Crafting 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= "/></p> <input type=" Submit "value=" Send "></form><?phprequire (' footer.html ');? >


Second, processing the form-let a page simultaneously display and process the form

To use a conditional statement:

if (Form submit) {process Form}

else {Show Form}


Example: Simple user name-password authentication


Input: User name: YF Password: 123456

Display: Login Successful

Drawing:




Code: ws.php (where header.html,footer.html refers to the template above):

<?phpdefine (' TITLE ', ' Login '), require (' header.html '), if (Isset ($_post[' submitted ')) {if (!empty ' name ' ]) && (!empty ($_post[' password '))) {if ((Strtolower ($_post[' name ')] = = ' YF ') && ($_post[' password ') = = ' 123456 ')) {//Name and password is 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 = "/></p>"  <p>password:<input type= "Password" name= "Password" "size="/></p> <input type= "Submit" value= "send" > <input type= "hidden" name= "submitted" value= "true"/></form> ';} Require (' footer.html ');? >



PHP Basic Tutorial--2 Creating templates, working with forms

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.