Cookies?

The username and email address are the only 2 fields that ‘retain’ or stay if someone forgets to fill out a required field. What do I need to add to keep all fields that are filled stay or retain if one forgets to fill out 1 or 2 required fields?

[php]<?php

// load settings
include_once(‘settings.php’);

class zubrag_signup_form {

function zubrag_signup_form() {

$this->error = '';
$this->login = '';
$this->email = '';
$this->firstname = '';
$this->lastname = '';
$this->address1 = '';
$this->address2 = '';
$this->city = '';
$this->state = '';
$this->ZIP = '';
$this->country = '';

if (USE_EMAIL && !USE_USERNAME)
  die('"USE_USERNAME" must be set to "true" when "USE_EMAIL" is set to "true"');

}

function parse_user_input() {
$this->login = isset($_POST[‘access_login’]) ? $_POST[‘access_login’] : ‘’;
$this->pass = $_POST[‘access_password’];
$this->email = LOGIN_AS_EMAIL
? $this->login
: (isset($_POST[‘access_email’]) ? $_POST[‘access_email’] : ‘’);
$this->firstname = isset($_POST[‘access_firstname’]) ? $_POST[‘access_firstname’] : ‘’;
$this->lastname = isset($_POST[‘access_lastname’]) ? $_POST[‘access_lastname’] : ‘’ ;
$this->address1 = isset ($_POST[‘access_address1’]) ? $_POST[‘access_address1’] : ‘’;
$this->address2 = $_POST[‘access_address2’];
$this->city = isset ($_POST[‘access_city’]) ? $_POST[‘access_city’] : ‘’;
$this->state = $_POST[‘access_state’];
$this->ZIP = isset($_POST[‘access_ZIP’]) ? $_POST[‘access_ZIP’] : ‘’;
$this->country = isset($_POST[‘access_country’]) ? $_POST[‘access_country’] : ‘’;
// remove suspicious characters
$remove_chars = array("\n","\r", “\r\n”, ‘"’, “’”, ‘&’,’<’,’>’,’,’,’/’, ‘\’);
$this->login = str_replace($remove_chars, ‘’, $this->login);
$this->pass = str_replace($remove_chars, ‘’, $this->pass);
// convert to lowercase
$this->email = strtolower(str_replace($remove_chars, ‘’, $this->email));
}

function showSignupPasswordProtect() {
include(‘signup_header.php’);
include(‘signup_form.php’);
include(‘signup_footer.php’);
}

function validate_user_input() {
// login validation
if ($this->login === ‘’) {
$this->error = “Please enter login.”;
return false;
}
if ($this->firstname === ‘’) {
$this->error = “Please enter your first name.”;
return false;
}
if ($this->firstname === ‘’) {
$this->error = “Please enter your first name.”;
return false;
}
if ($this->lastname === ‘’) {
$this->error = “Please enter your last name.”;
return false;
}
if ($this->address1 === ‘’) {
$this->error = “Please enter your address.”;
return false;
}
if ($this->city === ‘’) {
$this->error = “Please enter your city.”;
return false;
}
if ($this->ZIP === ‘’) {
$this->error = “Please enter your ZIP code.”;
return false;
}
if ($this->country === ‘’) {
$this->error = “Please enter your country.”;
return false;
}

// password validation
if ($this->pass === '') {
  $this->error = "Please enter password.";
  return false;
}
if ($this->pass == $this->login) {
  $this->error = "Password should not match login.";
  return false;
}

// email validation
if (USE_EMAIL && preg_match('/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}/', $this->email) == 0) {
  $this->error = "Invalid email.";
  return false;
}

}

function load_users_list() {
// list of users
$users = @file(USERS_LIST_FILE);
if ($users) {
// remove php “die” statement (hackers protection)
unset($users[0]);
}

// prepare users list
$this->LOGIN_INFORMATION = array();
foreach ($users as $user) {
  $u = explode(',',$user);
  $this->LOGIN_INFORMATION[trim($u[0])] = trim($u[1]);
}

}

function validate_user() {
// check if user exists
foreach($this->LOGIN_INFORMATION as $key => $value) {
if ($key == $this->login) {
$this->error = “Username $key already taken.”;
return false;
}
}
}

function save_user() {
// save user to database
$fusers = fopen(USERS_LIST_FILE,‘a+’);
if (!$fusers) {
$this->error = “Cannot add user to database.”;
return false;
}
fputs($fusers, “\n” . $this->login. ‘,’ . $this->pass . ‘,’ . $this->email . ‘,’ . $this->firstname . ‘,’ . $this->lastname . ‘,’ . $this->address1 . ‘,’ . $this->address2 . ‘,’ . $this->city . ‘,’ . $this->state . ‘,’ . $this->ZIP . ‘,’ . $this->country);
fclose($fusers);
}

function redirect() {
header('Location: ’ . SIGNUP_THANKS_URL);
exit();
}

}

$signup_form_instance = new zubrag_signup_form();

if (isset($_POST[‘access_password’])) {

while (true) {
$signup_form_instance->parse_user_input();
if ($signup_form_instance->error) break;

$signup_form_instance->validate_user_input();
if ($signup_form_instance->error) break;

$signup_form_instance->load_users_list();
if ($signup_form_instance->error) break;

$signup_form_instance->validate_user();
if ($signup_form_instance->error) break;

$signup_form_instance->save_user();
if ($signup_form_instance->error) break;

$signup_form_instance->redirect();

break;

}

if ($signup_form_instance->error) $signup_form_instance->showSignupPasswordProtect();

}
else {

// show signup form
$signup_form_instance->showSignupPasswordProtect();

}

?>
[/php]

Nevermind, I figured it out! Had to add a echo to the rest of the fields on the actual signup form

[php] *First Name:
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service