Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set up databank connection
- require_once '../../php/DBconfig.php';
- // Define variables and initialize with empty values
- $fields = array("username","password","confirm_password","firstname","lastname","email","confirm_email","birthday","gender");
- $params = array();
- $param_errs = array();
- $param_valid = array();
- foreach ($fields as &$v1) {
- $params[$v1] = "";
- $param_errs[$v1] = "";
- $param_valid[$v1] = FALSE;
- }
- // Processing form data when form is submitted
- if($_SERVER["REQUEST_METHOD"] == "POST") {
- foreach ($fields as &$v1) {
- echo $v1;
- $params[$v1] = trim($_POST[$v1]);
- }
- // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
- $validateUsername = function ($params, $param_errs, $param_valid, $link /*DB*/) {
- /*validates if the entered username is valid (by calling $params["username"],
- if not valid, put error message in $param_errs["username"],
- if valid, $param_valid["username"] = True; */
- };
- $validatePassword = function ($params, $param_errs, $param_valid) {
- //checks if the entered password is valid
- };
- $validateConfirmPassword = function ($params, $param_errs, $param_valid) {
- //checks if the entered password matches the first one
- };
- $validator = array(
- "username" => $validateUsername,
- "password" => $validatePassword,
- "confirm_password" => $validateConfirmPassword
- );
- // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
- // validates all fields
- foreach ($fields as &$v1) {
- $validator[$v1]($params, $param_errs, $param_valid, $link);
- }
- // Check input errors before inserting in database
- if (!in_array(False, $param_valid)) {
- // registers new user
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <!-- left out this code -->
- </head>
- <body>
- <!-- left out this code, register form is here -->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement