The verification and validation requires a little more explaination becuase it uses a regular expression to test for a valid email address. The first part of the email just checks to be sure that they even enter something and if they did then the else statement checks to see that the email is in a valid format namely a group or alphanumeric or printable charactersthen a "@" symbol then more alphanumeric characters and a "."followed by alphabetic characters. the "," seperating the regex then gives the second part with is theemail to check against. If this test fails then the user will see the form redisplayed with the message "The email you entered was not in the proper format!" will show in red.
If there are no errors the last if condition checks if the $error variable is empty or blank and if so then you would remove the comment the(//) in front of the echo "<.... and change the URL to the page you want the user to use. Finally all the concatenated
$errors are printed by the else statement. So now all that is left is to write the HTML form. and it is below and is tacked just below the code above these explainations. NOTE Just copy and paste the first section of code and then copy and paste the HTML below right after the the ?> closing tag.
<form action="form.php" method="post"> <table border="1" cellpadding="2" bgcolor="azure"><!--Put a nice border areound the table and add soft color--> <tr> <td width="20%" align="right">First Name</td> <td width="80%"> <input type="text" name="firstname" size="20" value="<?php echo $_POST[firstname] ?>"></td><!--NOTICE the php in the values--> </tr> <tr> <td width="20%" align="right">Last Name</td> <td width="80%"> <input type="text" name="lastname" size="20" value="<?php echo $_POST[lastname] ?>"></td><!--will echo users input for repopulation--> </tr> <tr> <td width="20%" align="right">Username</td> <td width="80%"> <input type="text" name="username" size="20" value="<?php echo $_POST[username] ?>"> (must be between 6 an 12 characters)</td> </tr> <tr> <td width="20%" align="right">Password</td> <td width="80%"> <input type="password" name="password" size="20" value="<?php echo $_POST[password] ?>"> (Password must be at least 6 characters)</td> </tr> <tr> <td width="20%" align="right">E-mail</td> <td width="80%"> <input type="text" name="email" size="40" value="<?php echo $_POST[email]; ?>"></td><!--Give more room for long emails--> </tr> <tr> <td width="20%" align="right"> </td> <td width="80%"> <input type="submit" value="" name="submit"></td> </tr> </table> <h3>The Username Password and the E-mail fields are required!</h3> </form>
Using the code above as a model you can modify it to suit your needs for your own site. The regex used to validate I found at the Zend site and is meant to work with .be or .any two or three character extension in a URL I have just finished working on a script that repopulates checkbox data. After looking all over the net for a tutorial or even asking in forums to make it work, I built my own that works like I want, so if there are enough requests I will post it along with explainations and comments. It takes four pages of code to work, but two of them are almost identical it is just that one inserts data and the other updates the database.
Edited by Houdini, 23 May 2006 - 11:50 AM.