customise Popup window to contain reported errors - php

imagine i have an errors array to contain any errors from a registration form, and i have a function called output_errors(), whose argument is the errors array.
is there a way to customise a pop up window to display the function to display the errors?
<?php
$error = array();
function output_errors($errors) {
return '<ul><li>' . implode('</li><li>',$errors) . '</li></ul>';
}
if (user_exists($_POST['username']) === true) {
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces.';
}
if (strlen($_POST['password']) < 6) {
$errors[] = 'Your password must be at least 6 characters';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your passwords do not match';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true) {
$errors[] = 'Sorry, email \'' . $_POST['email'] . '\' exists.';
}
if (empty($_POST) === false && empty($errors) === true) {
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email']
);
register_user($register_data);
header('Location: register.php?success');
exit();
} else if(empty($errors) === false) {
echo output_errors($errors);
?>
<form action="" method="post">
<ul>
<li>
<i>*All fields marked with asterisk are required!</i><br>
<input type="text" placeholder="Username" name="username">
</li>
<li>
<br>
<input type="password" placeholder="*Password" name="password">
</li>
<li>
br>
<input type="password" placeholder="*Retype Password" name="password_a">
</li>
<li>
<br>
<input type="text" placeholder="*First name" name="first_name">
</li>
<li>
<br>
<input type="text" placeholder="Last name" name="last_name">
</li>
<li>
<br>
<input type="text" placeholder="*Email" name="email">
</li>
<li>
<input type="submit" value="Register">
</li>
</ul>
</form>

You can't customize the by-default pop-up of JavaScript, either you can use Bootstrap or do something like:
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test!</button>
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=200, height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
}
</script>
</body>
</html>
In the document.write(content), here content will be your error message.
You can insert your php in js by doing:
document.write(<?php echo "Text"; ?>);
See if that helps.

I'm not sure if this is what you're looking for but if you replace the echo statement in the last line with this:
echo "<script>";
echo "window.open('', 'MsgWindow', 'width=200, height=100').document.write('" . output_errors($errors) . "');";
echo "</script>";
You will get a pop-up window with the errors displayed in it. That being said there are a few errors in your code which make the errors display immediately, specifically your password fields. So the above will work but you'll have a pop-up window as soon as the page is loaded.

Related

Failing to register and login

http://170.178.197.250/~devdegree/index.php
Using a form from phpacademy and feel free to visit the temp url and hopefully help me out here.
The problem is that there is a valid database connecting to this website, I enter the fields and it just stays on the register.php file.
Same applies when I create a user from the database itself then use that info to login and again the same problem applies.
This is about 2 years old and it worked for me last year and if there's any files you need to look at I'll reply with the script on here if need be but hopefully it's simply enough.
register.php
<?php
include 'core/init.php';
logged_in_redirect();
include 'includes/overall/header.php';
if (empty($_POST) === false) {
$required_fields = array('username', 'password', 'password_again', 'first_name', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Fields marked with an asterisk are required';
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true) {
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces.';
}
if (strlen($_POST['password']) < 6) {
$errors[] = 'Your password must be at least 6 characters';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your passwords do not match';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true) {
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use';
}
}
}
?>
<h1>Register</h1>
<?php
if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'email_code' => md5($_POST['username'] + microtime())
);
register_user($register_data);
header('Location: register.php?success');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action="" method="post">
<ul>
<li>
Username*:<br>
<input type="text" name="username">
</li>
<li>
Password*:<br>
<input type="password" name="password">
</li>
<li>
Password again*:<br>
<input type="password" name="password_again">
</li>
<li>
First name*:<br>
<input type="text" name="first_name">
</li>
<li>
Last name:<br>
<input type="text" name="last_name">
</li>
<li>
Email*:<br>
<input type="text" name="email">
</li>
<li>
<input type="submit" value="Register">
</li>
</ul>
</form>
<?php
}
include 'includes/overall/footer.php'; ?>
Again, any other files (there's around 20+) then I'll have a look into showing you if it means you can understand and help me out.
Big thanks,
Dev.
I cant see an action on your form to the register.php. Try adding one like "action="register.php""
Look from the current website you linked the form post correctly to register.php.
Nothing is not working.
You should check your machine for httpd ( or whatever are you using ) logs.
Maybe some warning or some fatalerror of php can explain the problem.
From this code and the website nothing looks wrong.

Show popup message without resetting the form

Currently I created registration form. The problem was if I enter the form wrongly, it shows an error message at the top of the form and the form
You can view my full code here
<?php
include 'core/init.php';
logged_in_redirect();
include 'includes/overall/header.php' ;
//if form is being submitted
if(empty($_POST)=== false)
{
//to validate whether user enters smtg or not otherwise no point continue to do the next validation
//create an array
$required_fields = array ('username','password','password_again','first_name','email','passport','gender','contactno','address');
foreach($_POST as $key=>$value)
{
//if the key (value) in array of $required_fields is true which is empty
if(empty($value) && in_array ($key, $required_fields) === true )
{
$errors[] = 'Fields marked with an asterisk are compulsory!';
//the validation can happen to more than 1 field
break 1;
}
}
if(empty($errors) === true)
{
if(user_exists($_POST['username']) === true)
{
$errors[] = 'Sorry, the username \'' .$_POST['username'] . '\' is already taken.';
}
//search for the string, preg_match(search_pattern, your_string)
// \s = white space character
//if(preg_match("/\\s/", $_POST['username']) == true)
if(preg_match("/\s/", $_POST['username']) == true)
{
$errors[] = 'Your username must not contain space.';
}
if(strlen($_POST['password']) < 6)
{
$errors[] = 'Your password must be at least 6 characters';
}
if($_POST['password'] !== $_POST['password_again'])
{
$errors[] = 'Your passwords do not match at all';
}
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false)
{
$errors[] = 'A valid email address is required';
}
if(email_exists($_POST['email']) === true)
{
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.';
}
if(preg_match("/\s/", $_POST['passport']) == true)
{
$errors[] = 'Your passport must not contain space!!.';
}
else if(preg_match("/\s/", $_POST['gender']) == true)
{
$errors[] = 'Your gender must not contain space.';
}
else if (!preg_match('/^[0-9]\d{9}$/', $_POST['contactno']))
{
$errors[] = 'Enter your contact number correctly!!.';
}
}
}
//what does this line does is that to check whether success is in the end of the URL
if(isset($_GET['success']) && empty($_GET['success']))
{
echo 'You have been registered successfully! You may login now';
}
else
{//if there are no errors
if (empty($_POST) === false && empty($errors) === true)
{
//create an array of $register_data for sanitizing purpose ,prevent SQL injection attactk
$register_data = array
(
'username' => $_POST['username'],
'password' => $_POST['password'],
'passport' => $_POST['passport'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'gender' => $_POST['gender'],
'email' => $_POST['email'],
'contactno' => $_POST['contactno'],
'address' => $_POST['address']
);
register_user($register_data);
//redirect and bring success variable to register.php
header('Location: register.php?success');
exit();
}
//
else if (empty($errors) === false)
{
echo output_errors($errors);
}
?>
<form action="" method="post">
<ul>
<li>
Username*:<br>
<input type="text" name="username">
</li>
<li>
Password*:<br>
<input type="password" name="password">
</li>
<li>
Password again*:<br>
<input type="password" name="password_again">
</li>
<li>
<table width="200" border="0">
<tr>
<td width="157" scope="col">First name*: <br>
<input type="text" name="first_name"> </td>
<td width="439" scope="col">Last name: <br>
<input type="text" name="last_name"> </td>
</tr>
<tr>
<td><p>Gender*:
<select name="gender" id="gender">
<option value="">Select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</p></td>
<td> </td>
</tr>
<tr>
<td>Passport: <br>
<input type="text" name="passport"></td>
<td> </td>
</tr>
<tr>
<td><p>Email*:<br>
<input type="text" name="email">
</p></td>
<td><p>Contact No*:<br>
<input type="text" name="contactno" id="contactno">
</p></td>
</tr>
<tr>
<td colspan="2"><p>Address*<br>
<input name="address" type="text" size="100">
</p></td>
</tr>
</table>
</li>
<li>
<input type="submit" value="Register">
</li>
</ul>
</form>
<?php
}
include 'includes/overall/footer.php' ; ?>
Now I want to change to show pop up message without reset the form.
Is there any solution to do so?
It will be good if you give form input tags like this :
<input type="text" name="username" placeholder="Username" value="<?php echo $_POST['username']; ?>">
and similarly for other fields except password.
OR
<input type="text" name="username" placeholder="Username" value="<?php echo (isset($_POST['username'])?$_POST['username']:''); ?>">
it will keep your form data if there is some kind of error and you have not validated the form.
PHP is a Server Side processing language. There is no way to process the PHP Code on the client without submitting the form.
However, you can accomplish what you want to using Javascript, which will run client side, and can pop up an alert (or a pop up) to indicate what is wrong with the form before the user submits the form.
There are some great library suggestions, and some great samples of that in this question here: Javascript form validation

PHP Header Location not working on live server [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I have a simple registration form set up, on sending the details to my function to put the data in the database I want the page to redirect to a success page...
This works brilliantly on my local server but when I uploaded it to my live server its just not redirecting
The redirect that is not working is on line 65 :) it just redirects to register.php?success
Any help would be gratefully received. I've seen a few people have had the same problem but their solution would not work for me :(
ALL other header locations work. just this one won't :#
<?php
include 'core/init.php';
//check if logged in
logged_in_redirect();
include 'includes/overall/header.php';
if (empty($_POST) === FALSE) {
$required_fields = array('username', 'password', 'password_again', 'first_name', 'last_name', 'email');
foreach ($_POST as $key => $value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'You appear to have missed something out, all fields are required.';
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true ) {
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.';
}
if (strlen($_POST['username']) < 6) {
$errors[] = 'Sorry, your username must be at least 6 characters.';
}
if (strlen($_POST['username']) > 25) {
$errors[] = 'Sorry, your username must be under 25 characters.';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces.';
}
if (strlen($_POST['password']) < 6) {
$errors[] = 'Sorry, your password must be at least 6 characters.';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Sorry, your passwords do not match.';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false ) {
$errors[] = 'Sorry, you did not provide a valid email address.';
}
if (email_exists($_POST['email']) === true ) {
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already registered to an account.';
}
}
}
?>
<h1>Register</h1>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
echo "You have been registered successfully.";
} else {
if (empty($_POST) === false && empty($errors) === true) {
// register user
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'email_code' => md5($_POST['username'] + microtime())
);
register_user($register_data);
//header location not working *********************
header('Location: register.php?success');
exit();
} else if (empty($errors) === false) {
//error output
echo output_errors($errors);
}
?>
<form action="" method="post">
Register your account here, all fields are required.
<ul>
<li>
Username: </br>
<input type="text" name="username"/>
</li>
<li>
Password: </br>
<input type="password" name="password"/>
</li>
<li>
Repeat Password: </br>
<input type="password" name="password_again"/>
</li>
<li>
First Name: </br>
<input type="text" name="first_name"/>
</li>
<li>
Last Name: </br>
<input type="text" name="last_name"/>
</li>
<li>
Email: </br>
<input type="text" name="email"/>
</li>
<li>
<input type="submit" value="Register"/>
</li>
</ul>
</form>
<?php
}
include 'includes/overall/footer.php';
?>
Most likely, output buffers are on in the development environment and off in the live environment. Also, displaying errors to users must be off in the live environment or the exact error (output started before headers) would have shown up in the browser.
Check you ini file for this stuff: http://php.net/manual/en/outcontrol.configuration.php
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Contact form issues

I'm having all kinds of issues with contact form. When I test on my home server everything runs smoothly. Once I upload it online it doesn't work. First there were problems with headers and now apparently "This web page has a redirect loop".
Here's my code. Please advice me what to do.
Thanks.
<?php
// Title: Contact Form - Dolce Forno GB
// Updated: 5/9/2012
//Validation code
if (!empty($_POST)) {
$errors = array();
//variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
//All field are required
if (empty($name) === true || empty($email) === true || empty($phone) === true || empty($subject) === true || empty($message) === true ){
$errors[] = 'Please fill in all the fields.';
}
else {
//This regex allows only: a-z,A-Z, space, comma, full stop, apostrophe, dash
if (!preg_match("/^[a-zA-Z\s,.'-]+$/", $name)) {
$errors[] = 'Invalid name.';
/*die ("Invalid name."); */
}
//var_filter php function
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Invalid email address.';
}
//This regex allows only: 0-9, space, dash, brackets, min-max length: 10-15
if (!preg_match("/^[0-9\s]{10,15}$/", $phone)){
$errors[] = 'Invalid phone number.';
}
}
}
if (empty($errors)) {
//send email
mail('info#dolcefornogb.com', 'Contact Form', $subject, 'Message:' . $message,'From: ' . $name . $email . $phone);
header('Location:mail.php?sent');
exit ();
}
print_r($errors);
?>
<DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
if (isset($_GET['sent']) === true) {
echo '<p>Thanks for contacting us!</p>';
}
else {
if (!empty($errors)){
echo '<ul>';
foreach ($errors as $error){
echo '<li>', $error,'</li>';
echo '</ul>';
}
}
?>
<form action="" method="post">
<p> <label for="name">Name
<span class="small">Add your name </span></label>
<input type="text" name="name" id="name"
<?php
if(isset($_POST['name']) === true){
echo 'value="', strip_tags($_POST['name']),'"';
}
?>
>
</p>
<p> <label for="email">E-mail address
<span class="small"> Add your e-mail</span></label>
<input type="text" name="email" id="email"
<?php
if(isset($_POST['email']) === true){
echo 'value="', strip_tags($_POST['email']),'"';
}
?>
>
</p>
<p><label for="phone">Phone<span class="small"> Add your phone number</span></label>
<input type="text" name="phone" id="phone"
<?php
if(isset($_POST['phone']) === true){
echo 'value="', ($_POST['phone']),'"';
}
?>
>
</p>
<p><label for="suject">Subject </label>
<input type="text" name="subject" id="subject"
<?php
if(isset($_POST['subject']) === true){
echo 'value="', strip_tags($_POST['subject']),'"';
}
?>
>
</p>
<p><label for="message">Message:</label>
<textarea name="message" id="messgae" rows="10" cols="50">
<?php
if(isset($_POST['message']) === true){
echo strip_tags($_POST['message']);
}
?></textarea>
</p>
<p><label for="call">Request Phone Call</label>
Yes:<input type="radio" value="Yes" name="call">
No:<input type="radio" value="No" name="call">
</p>
<p class="buttons">
<input type="submit" value="Send"> <input type="reset" value="Clear">
</p>
</form>
<?php
}
?>
Try redirecting to a different page with just the success message in it.
i.e. replace
header('Location:mail.php?sent');
with
header('Location:mail-success.php?sent');
Then get rid of (move to the new page)
if (isset($_GET['sent']) === true) {
echo '<p>Thanks for contacting us!</p>';
}
Also try adding 303 status to the header call
http://www.electrictoolbox.com/php-303-redirect/

AJAX echo not returning but php register to database works

UPDATE:
Code is written as is and will stay that way. However, now it doesn't submit the data the user wrote in the form to the database. What's wrong.
Here is the first file. It contains the XML HTTP REQUEST and html form. This file also contains the wild .
<!DOCTYPE html>
<html>
<head>
<?php
require_once 'core/init.php';
?>
<meta charset="utf-8" />
<title></title>
<script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js">
//directly below is that wild script tag
</script>
<script type="text/javascript">
function load(thefile, thediv) {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject ('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById(thediv).innerHTML = xmlhttp.responseText;
}
}
parameters1 = 'username='+document.getElementById('username').value;
parameters2 = 'email='+document.getElementById('email').value;
parameters3 = 'password='+document.getElementById('password').value;
parameters4 = 'password_again='+document.getElementById('password_again').value;
parameters5 = 'first_name='+document.getElementById('first_name').value;
parameters6 = 'last_name='+document.getElementById('last_name').value;
xmlhttp.open('POST', thefile, true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send(parameters1 + '&' + parameters2 + '&' + parameters3 + '&' +
parameters4 + '&' + parameters5 + '&' +parameters6);
}
</script>
</script>
<title>Pop Up Sign Up</title>
</head>
<body>
<div id="popupbox">
<form name="signup" action="" method="post">
Desired Username:
<input id="username" placeholder="Username" value="<?php echo
(isset($desired_username) ? strip_tags($desired_username) : '');?>" type="text"
placeholder="Bob123" name="username" size="14" />
<br /> <br />
Your Email:
Register
<input id="email" placeholder="jasontanner328#gmail.com" value="<?php echo
(isset($desired_email) ? strip_tags($desired_email) : '');?>" type="email"
name="email" size="14" />
<br /> <br />
Your Password:
<input id="password" placeholder="Password" name="password" type="password"
size="14" />
<br /> <br />
Your Password Again:
<input id="password_again" placeholder="Password Again"
name="password_again" type="password" size="14" />
<br /> <br />
First Name:
<input id="first_name" placeholder="Jason" value="<?php echo
(isset($desired_first_name) ? strip_tags($desired_first_name) : '');?>"
name="first_name" type="text" size="14" />
<br /> <br />
Last Name:
<input id="last_name" placeholder="Tanner" name="last_name" value="<?php echo
(isset($desired_last_name) ? strip_tags($desired_last_name) : '');?>" type="text"
size="14" />
<br /> <br />
<center><input type="button" name="submit" value="Register"
onclick="load('register.php', 'popupbox');" /></center>
</form>
</div>
<span id="result">
</span>
</body>
</html>
Here is the second file that deals with inserting the data into the server and what I want to return after the submit button has been clicked on.
<?php
require_once 'core/init.php';
logged_in_redirect();
if (empty($_POST) === false) {
$desired_username = $_POST['username'];
$desired_email = $_POST['email'];
$desired_first_name = $_POST['first_name'];
$desired_last_name = $_POST['last_name'];
$required_fields = array
('username','email','password','password_again','first_name','last_name');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Fields marked with an asterisk are required.';
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true || strlen($_POST ['username']) < 6) {
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken
or is too short. 6 characters are the minimum.';
}
if (preg_match("/\\s/", $_POST ['username']) == true) {
$errors[] = 'Sorry there is a space in your username.';
}
if (strlen($_POST ['password']) < 6) {
$errors[] = 'Your password must be at least 6 characters';
}
if ($_POST ['password'] !== $_POST['password_again']) {
$errors[] = 'Make sure both passwords submitted are the same.';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required.';
}
if (email_exists($_POST['email']) === true) {
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.';
}
if (strlen($_POST ['first_name']) < 2) {
$errors[] = 'Your first name must contain at least two characters.';
}
if (strlen($_POST ['last_name']) < 2) {
$errors[] = 'Your last name must contain at least two characters.';
} }
} else {
//if (isset($_GET['success']) && empty($_GET['success'])) {
//echo 'You have successfully registered. Please check your email to activate your
account.';
// } else {
if (empty ($_POST) === false && empty($errors) === true){
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'email_code' => md5($_POST['username'] + microtime())
);
register_user($register_data);
echo 'WIN';
// header('Location: register.php?success');
// exit();
// } else
if (empty($errors) === false){
echo output_errors($errors);
}
}}
?>
The button on your form is type="submit"; This will submit the form and redirect the page, unless you have it return false; in the onclick attribute. I would suggest, rather, to change the button to a regular button instead of a submit-button:
<input type="button" name="submit" value="Register" onclick="load('register.php', 'result');" />
This change will stop your page from redirecting after submitting the form.
EDIT: After reviewing the full code, the POST-page looks like it has a logic error in the processing (and a few syntax errors; see my comment on the question regarding closing curly braces).
The if (empty($errors) === true) { block ends with an } else { and inside the else-block you output that the user has successfully registered. Translated, this means "if there is an initial error, tell the user they successfully registered." Instead, change everything after (and including) the } else { to:
if (!empty($_POST) && empty($errors)) {
// the form has been submitted and there are no errors
echo 'You have successfully registered. Please check your email to activate your account.';
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'email_code' => md5($_POST['username'] + microtime())
);
register_user($register_data);
} else if (!empty($errors)) {
// there are errors =[
echo output_errors($errors);
}

Categories