php学习笔记(十六)登录页面实例-输入检查和粘性表单

粘性表单会记住输入到其中的值,当用户输入错误而没能准确完成表单,从而需要重新提交时,可能就需要使用粘性表单了。表单第一次运行时什么都不打印,因为变量没有值,如果表单在提交后再次出现,则用户之前的输入会自动显示出来。


welcome to register

"; //添加css样式,错误信息显示红色 print ''; //检查表单是否提交 if ($_SERVER['REQUEST_METHOD'] == 'POST') { $problem = false;//指示是否有错误 //检查每一个值 if (empty($_POST['firstname'])) { $problem = true; print '

please enter your first name

'; } if (empty($_POST['lastname'])) { $problem = true; print '

please enter your last name

'; } if(empty($_POST['email'])) { $problem = true; print '

please enter your emial

'; } if (empty($_POST['password1'])) { $problem = true; print '

please enter password

'; } if (empty($_POST['password2'])) { $problem = true; print '

please confirm password

'; } if ($_POST['password1'] != $_POST['password2']) { $problem = true; print '

confirm did not match password

'; } //判断是否有错误发生 if (!$problem) { print"

you are now registered

"; }else { print "

please try again

"; } } ?>

First Name:

Last Name:

Email Address:

Password:

Confirm Password:




你可能感兴趣的:(php学习笔记(十六)登录页面实例-输入检查和粘性表单)