Hi All,
I am trying to use a method that a form self posts and checks the data to an errors array see this post.
The issue I am having is that is not checking the errors array (in my errors.php include) and if I submit the data, it goes on to the process page.
I tried re--use the example NogDog gave me, but so far it is not correct.
Here is the self include code.
if(isset($_POST['Submit']))
{
include"../includes/errors.php";
if(count($errors) == 0) // no errors
{
include('newsletter_process.php'); // process input from Form #1
}
if(isset($_POST['Reset']))
{
$_SESSION = array();//initalize the array
session_destroy();//reset was pressed, destroy all the session data
}
require 'newsletter_signup.php'; // re-displays Form #1
include"../includes/errors.php";
if($_SESSION['Done'] ==1) {
exit;
}
} else {
if(isset($_POST['Reset']))
{
$_SESSION = array();//initalize the array
session_destroy();//reset was pressed, destroy all the session data
}
require 'newsletter_signup.php'; // re-displays Form #1
include"../includes/errors.php";
}
My files are
(newsletter_signup.php - the form)
(errors.php - the error function and array)
(newsletter_process.php - process page)
Here is the errors page.
function errors($field_name, $error_message)
{
global $errors;
if(!isset($_POST[$field_name]) || ( trim($_POST[$field_name]) == '') )
{
$errors[$field_name] = '<font face="Arial" color="#FF0000" size="+1"> ' . $field_name
. '<-' . $error_message . '</font>';
}
}
if(isset($_POST['EltrSelect'])) { //see if they selected Eletter option
$emailaddress = errors('EmailAddress', 'Please provide a valid email address.');
}
if(isset($_POST['PrintLtrSelect'])) { //see if they selected Print option
$firstname = errors('PrintFirstName', 'Please enter your first name.');
$lastname = errors('PrintLastName', 'Please enter your last name.');
$address1 = errors('Address1', 'Please enter your address."');
$city = errors('City', 'Please enter your city.');
$state = errors('State', 'Please choose your state.');
$zip = errors('Zip', 'This is a required field.');
}
and an example of one of the form elements.
if(!empty($errors['EmailAddress'])) {
echo '<span class="style1">Email Address:</span>';
} else {
echo 'Email Address:';
}
and the input field.
[code=php]
<input name="EmailAddress" id="EmailAddress" style="float: left" tabindex="4"
size="45" value=
<?php if(!empty($_POST['EmailAddress'])) {
echo $_SESSION['EmailAddress'];
?
"/>
I check to see if the selected a checkbox before assigning the errors to the array .
if(isset($_POST['EltrSelect'])) { //see if they selected Eletter option
$emailaddress = errors('EmailAddress', 'Please provide a valid email address.');
}
for example, then I check to make the field is filled out.
I hope I made this clear enough.
As always, I appreciate the help.
regards,
Don