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