Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [insert_php]
- // Initialise variables
- $name = "";
- $password = "";
- $email = "";
- $phone = "";
- $how = "";
- $type = "";
- // Sanitise fields
- if($_SERVER["REQUEST_METHOD"] == "POST")
- {
- $name = test_input($_POST["inputUsername"]);
- $password = test_input($_POST["inputPassword"]);
- $email = test_input($_POST["inputEmail"]);
- $phone = test_input($_POST["inputPhone"]);
- $how = test_input($_POST["inputHow"]);
- $type = test_input($_POST["inputType"]);
- }
- // Validate fields
- registration_validation(
- $name,
- $password,
- $email,
- $phone,
- $how,
- $type
- );
- // Attempt to submit to database.
- complete_registration(
- $name,
- $password,
- $email,
- $phone,
- $how,
- $type
- );
- // Strip any special characters out of the input.
- function test_input($data)
- {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- // Do specific checks e.g. length of username etc.
- function registration_validation($name, $password, $email, $phone, $how, $type)
- {
- global $reg_errors;
- $reg_errors = new WP_Error;
- if (empty($name) || empty($password) || empty($email) || empty($phone) || empty($how) || empty($type))
- {
- $reg_errors->add('field', 'Required form field is missing');
- }
- if (is_wp_error($reg_errors))
- {
- foreach ($reg_errors->get_error_messages() as $error)
- {
- echo '<div>';
- echo '<strong>ERROR</strong>:';
- echo $error . '<br/>';
- echo '</div>';
- }
- }
- }
- // Submit to the database.
- function complete_registration($name, $password, $email, $phone, $how, $type)
- {
- global $reg_errors;
- if ( 1 > count( $reg_errors->get_error_messages() ) )
- {
- $userdata = array(
- 'user_login' => $name,
- 'user_email' => $email,
- 'user_pass' => $password,
- 'user_phone' => $phone,
- 'user_type' => $type,
- 'user_how' => $how
- );
- $user = wp_insert_user( $userdata );
- echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
- }
- }
- [/insert_php]
- <form method="post" action="[insert_php] echo htmlspecialchars($_SERVER["PHP_SELF"]);[/insert_php]">
- <div class="form-group">
- <label for="inputUsername">Username</label>
- <input type="text" class="form-control" id="inputUsername">
- </div>
- <div class="form-group">
- <label for="inputPassword">Password</label>
- <input type="password" class="form-control" id="inputPassword">
- </div>
- <div class="form-group">
- <label for="inputEmail">Email</label>
- <input type="email" class="form-control" id="inputEmail" aria-describedby="emailHelp" placeholder="name@example.com">
- </div>
- <div class="form-group">
- <label for="inputPhone">Contact Phone Number</label>
- <input type="password" class="form-control" id="inputPhone">
- </div>
- <div class="form-group">
- <label for="how">How did you hear about us?</label>
- <select class="form-control" id="how">
- <option>Word of mouth</option>
- <option>Local paper</option>
- <option>Search engine</option>
- <option>Other</option>
- </select>
- </div>
- <div class="form-group">
- <label for="signupType">I am a:</label>
- <select class="form-control" id="signupType">
- <option>Parent / Guardian</option>
- <option>Student</option>
- </select>
- </div>
- <button type="submit" value="Submit" class="btn btn-primary">Submit</button>
- </form>
Add Comment
Please, Sign In to add comment