Page 1 of 1

redirect unsets session variables

Posted: Wed May 13, 2009 10:02 am
by lubber123
I have a form that posts to the same page. When it is posted it hits a section called "Update". The update sets session variables off the $_POST variables. Then it validates the POST variables. If an error is found it redirects the page back to itself with an error message otherwise it updates the DB and unsets the session variables for the next session. The form textboxes and checkboxes are scripted so that if the variables associated with the textbox are set, they are sown or the checkbox is checked. If I comment out the validate section and simply post the form to itself and set the session variables - the variables are shown in the textboxes - everything works. However, If the validate section redirects back to the page with an error message the session variables seem to get unset and the text and checkboxes don't show the variables. I have been trying to figure this out for days.

Any help will be great.

Here is the "update" section code:

Code: Select all

case "update":
                set_session_variables();
                validate_form();
                    --> UPDATE DB__
                }
Here is the validate code:

Code: Select all

 
if((isset($_POST['number']))  && ($_POST['number'] != "")){
            echo $_POST['number'];
        }else{
            unset($_SESSION['number']);
            $error_msg = "Please provide the number of people expected to eat at the event.";
                    header('LOCATION: eventchecklist-create-food.php?err=' . $error_msg);
                    exit;
        }
        if((isset($_POST['number'])) && ($_POST['number'] != "")){
            $_SESSION['number'] = $_POST['number'];
            if($_SESSION['number'] > 999){
            unset($_SESSION['number']);
                $error_msg = "The event lead name cannot be longer than 30 characters in length.";
                    header('LOCATION: eventchecklist-create-food.php?function=form&err=' . $error_msg);
                    exit;
            }
            if(!is_numeric($_SESSION['number'])){
            unset($_SESSION['number']);
                $error_msg = "The expected number that will be eating must be a NUMERIC number between 1 and 999.";
                header('LOCATION: eventchecklist-create-food.php?err=' . $error_msg);
                exit;
            }
        }else{
            unset($_SESSION['number']);
            $error_msg = "Please provide the number of people expected to be eating at the event.";
                header('LOCATION: eventchecklist-create-food.php?err=' . $error_msg);
                exit;
        }
 

Re: redirect unsets session variables

Posted: Wed May 13, 2009 11:47 am
by crazycoders
I won't tell you whats wrong but instead show you how i handle postbacks to my own pages... this is indeed the correct way of doing it. I don't say i've got the best solution but at least, i've been using it for years (about 5) and i never changed my way of doing it... here goes:

Part 1, seperate postbacks from gets

Code: Select all

 
<?php
//Include the header system control file
include('../includes/system.php');
 
//Setup the errors handling
$errors = array();
$allowedit = false;
 
//If not is postback
if(!$ispostback){
   //GET part
}else{
  //POST part
}
?>
<HTML>
 
... SOME HTML ....
 
<?php if(count($errors)>0){ ?>
<div class="errors">
    <div class="title"><?php echo $strings['generic']['operationfailed']; ?></div>
    <?php echo implode('<br />', $errors); ?>
</div>
<?php } ?>
<?php if(count($messages)>0){ ?>
<div class="messages">
    <?php echo implode('<br />', $messages); ?>
</div>
<?php } ?>
<?php if(count($errors)==0 || $allowedit == true){ ?>
...DISPLAY SOME STUFF HERE THAT YOU WOULD PREVENT IN CASE OF ERRORS
<?php } ?>
 
... MORE HTML ....
 
</HTML>
 
In the GET part, that is what i do for this page:

Code: Select all

 
    //Check if there is a applicant
    if(!isset($_REQUEST['applicantid']) || !is_numeric($_REQUEST['applicantid'])){ $_REQUEST['applicantid'] = 0; }
    if(md5('CAB'.$_REQUEST['applicantid'].'shed') != $_REQUEST['happlicantid']){ $errors[] = $strings['adminrh']['invalidid'].' (3)'; }
    
    //Get the data
    $applicant = mysql_query('SELECT * FROM jobapplicants WHERE id = '.$_REQUEST['applicantid']);
    if(mysql_num_rows($applicant) == 0){ 
        $_REQUEST['applicantid'] = 0;
        $errors[] = $strings['generic']['notfound'];
    }else{
        $applicant = mysql_fetch_assoc($applicant);
    }
    
    //Get the job data
    if(count($errors) == 0){
        $job = mysql_query('SELECT * FROM jobopenings WHERE id = '.$applicant['jobid']);
        if(mysql_num_rows($job) == 0){
            $errors[] = $strings['generic']['notfound'];
        }else{
            $job = mysql_fetch_assoc($job);
        }
    }
    
    //Get the cv data in case it was already done
    $applicantcv = mysql_query('SELECT * FROM jobapplicantscv WHERE applicantid = '.$_REQUEST['applicantid']);
    if(mysql_num_rows($applicantcv) != 0){ 
        $_REQUEST['applicantid'] = 0;
        $errors = array($strings['adminrh']['alreadydone']);
    }
    
    //Load to the post if found
    if(count($errors) == 0){
        $_REQUEST = $applicant;
        $_REQUEST['applicantid'] = $applicant['id'];
        $_REQUEST['tel1'] = $applicant['telephone'];
        $_REQUEST['tel2'] = $applicant['cellphone'];
        $_REQUEST['jobid'] = $job['id'];
    }
 
Part 2, postback analysis

Code: Select all

 
    //Analyse the posted information
    if(isset($_POST['cancel'])){ header('location: index.php'); exit(); }
    if(isset($_POST['submit'])){
        
        //Allow the edit after this information was process even if there are errors
        $allowedit = true;
        
        //Analyse the posted information for errors
        if(!isset($_POST['applicantid']) || !is_numeric($_POST['applicantid'])){ $errors[] = $strings['adminrh']['invalidid'].' (1)'; }
        if(!isset($_POST['happlicantid']) || !is_string($_POST['happlicantid'])){ $errors[] = $strings['adminrh']['invalidid'].' (2)'; }
 
... More validation code stripped you don't need all of it...
        
        //Analyse the dates if posted, no date is required, but if posted, it must have a correct format
        if(isset($_POST['disp']) && !empty($_POST['disp']) && datefrom($_POST['disp'], 1970, 1, 1, true, true, true) == false){ $errors[] = $strings['adminrh']['invaliddisp']; }
 
... More validation code stripped you don't need all of it...
        
        //Check that at least one of telephones are provided
        if($tel1invalid == true && $tel2invalid == true){
            $errors[] = $strings['adminrh']['invalidtelephones'];
        }
        
        //Get the jobid to see if it is real, only if not 0 because 0 = new
        if(md5('CAB'.$_POST['applicantid'].'shed') != $_POST['happlicantid']){
            $errors[] = $strings['adminrh']['invalidid'].' (3)';
        }
    
        //Get the data
        $applicant = mysql_query('SELECT * FROM jobapplicants WHERE id = '.$_REQUEST['applicantid']);
        if(mysql_num_rows($applicant) == 0){ 
            $_REQUEST['applicantid'] = 0;
            $errors[] = $strings['generic']['notfound'];
        }else{
            $applicant = mysql_fetch_assoc($applicant);
        }
    
        //Get the job data
        if(count($errors) == 0){
            $job = mysql_query('SELECT * FROM jobopenings WHERE id = '.$applicant['jobid']);
            if(mysql_num_rows($job) == 0){
                $errors[] = $strings['generic']['notfound'];
            }else{
                $job = mysql_fetch_assoc($job);
            }
        }
    
        //Get the cv data in case it was already done
        $applicantcv = mysql_query('SELECT * FROM jobapplicantscv WHERE applicantid = '.$_REQUEST['applicantid']);
        if(mysql_num_rows($applicantcv) != 0){ 
            $_REQUEST['applicantid'] = 0;
            $errors = array($strings['adminrh']['alreadydone']);
            $allowedit = false; //Disable back edit because it was already done before
        }
        
        //No errors? Insert/Update
        if(count($errors) == 0){
                
            //Insert
            mysql_query(...SQL....);
                
            //Mail the admins
            ... send a mail to the admins ...
 
            //Redirect to the job page
            header('location: jobs.php?msg=success&mailsuccess='.$mailsuccess);
            exit();
            
        }
        
    }
 
You can see something important in the postback, the part that checks if isset($_POST['cancel']) and isset($_POST['submit']) is where crucial actions are detected. It is there that the user's cancel or submit button that are pressed in the form are analysed.

If the user pressed cancel, i redirect, if the user pressed submit, i try to process, if there are errors? I do not do any redirect, i simply do not execute the actions and pursue validation to gather all possible errors. Since the errors are always declared but may be empty, the system just doesn't show errors until he actually does one!

Is it clear?

Re: redirect unsets session variables

Posted: Wed May 13, 2009 2:33 pm
by lubber123
Help me to understand this, how do the form variables (textboxes) hold their values? The form is actually posted when submitted correct? Or, does it not post but run the validation code? Am I being confusing? Also, I am not exactly sure how to show the error messages with this code.

Re: redirect unsets session variables

Posted: Wed May 13, 2009 2:37 pm
by crazycoders
Ohhh sorry, forgot to tell you that part...

All my forms always use $_REQUEST (which is a mix between $_GET / $_POST) to output their current values...

In the get part, i load the values into the $_REQUEST by doing:

Code: Select all

$_REQUEST = $myarrayofvalues;
And for the errors, look at this portion of code:

Code: Select all

 
<?php if(count($errors)>0){ ?>
<div class="errors">
<div class="title"><?php echo $strings['generic']['operationfailed']; ?></div>
<?php echo implode('<br />', $errors); ?>
</div>
<?php } ?>
 
You can see here that if the $errors array contains something, i implode it using <BR>s inside a div that styles these elements into a beautiful list of errors :)

Re: redirect unsets session variables

Posted: Wed May 13, 2009 5:41 pm
by lubber123
Let me try to convert my page into this format. Will you check it out for me? I am still not sure of how to display the errors from the array but will try. So you don't use any session variables? I have always used session variables to pass info from page to page.

Re: redirect unsets session variables

Posted: Thu May 14, 2009 8:09 am
by crazycoders
Session info is for session info, not page info...
Session = A user comes to your site and stays active within a certain limit of time and then when the limit is reached, a new session must start... So it pertains to the visitor, not to the visited page!

Re: redirect unsets session variables

Posted: Thu May 14, 2009 9:59 am
by lubber123
Okay, I am new to this and am trying to get my head around the logic. I use the session date for user's but, not knowing how to hold the data in the textbox I was using sessions. learning here. So, I presume that the SUBMIT section is only performed when the user hits the submit button. If an error is found it exits the SUBMIT section, setting off the errors and NOT performing the post.

Re: redirect unsets session variables

Posted: Thu May 14, 2009 10:03 am
by crazycoders
The POST is the user's action, the processing is what you do with the posted information. Applying the action that the user decided such as cancel and submit is part of the processing. If you detect errors in the processing, it's your job NOT to apply the action to the database, files, html being displayed, etc...

So in this case what we do is this:

1. Check if it's a GET or POST
2. In GET, just validate the request, load the info into the $_REQUEST
3. Output the form using $_REQUEST

1. Check if it's a GET or POST
2. In POST, validate the action intended by the user (cancel or submit)
3. If Cancel, redirect, if Submit, process the submit
4. Validate the POSTED information through $_REQUEST or $_POST and affect the data if need be
5. If there were errors, do not persist the changes to the database...
6. Redirect if no error to the resulting page
7. If there were errors, just go on in the page and let the page show again using the $_REQUEST variables posted by the user
8. If there are errors in the $errors array, the page will display them at the expected <DIV>

Is it more clear?

Re: redirect unsets session variables

Posted: Thu May 14, 2009 1:23 pm
by lubber123
You have totally changed the way I do this and it is so much simpler. The page is reflecting user input after the post and all. I am writing validation. Can you explain the errors section a little more. Do you define the errors somewhere i.e. "The date must be in the format ...", and then call it based on the error expressed during validation. Then you echo the errors, if there are any, based on the error label, or update the DB and redirect the page? I hope I am making sense.

Thanks for your help so far - this is great.

Re: redirect unsets session variables

Posted: Thu May 14, 2009 1:37 pm
by crazycoders
All my strings are kept in what i call a locale file. here is an example of a locale file:

Code: Select all

 
<?php
//English locale manager, load this file to have access to all english based formats and strings
setlocale(LC_ALL, 'en-CA', 'en', 'eng', 'english', 'ang', 'en-US');
function locale_date($timestamp){ if(!is_numeric($timestamp)){ $timestamp = strtotime($timestamp); } return strftime('%b %d %Y at %Hh%M', $timestamp); }
function locale_number($number, $decimals){ return number_format($number, $decimals, '.', ','); }
$strings = array(
    'generic' => array(
        'yes' => 'yes',
        'no' => 'no',
        'nodata' => 'No data available',
        'delete' => 'Delete',
        'view' => 'Show',
        'edit' => 'Edit',
        'new' => 'New',
        'otherlanguage' => 'Français',
        'back' => 'Back',
        'submit' => 'Submit',
        'cancel' => 'Cancel',
        'notfound' => 'The requested information doesn\'t exist or was deleted in between two operations, please press BACK to go back to the previous page and start over.',
        'operationsuccess' => 'Operation completed successfully',
        'operationfailed' => 'An error occured while processing the requested operation',
        'search' => 'Search',
        'searchtitle' => 'Search :',
        'validatedeleteoperation' => 'Please validate the attempted delete operation',
        'datepicker' => '',
    ),
    'langs' => array(
        '1033' => 'English',
        '3084' => 'French',
    ),
    'adminrh' => array(
        'title' => 'Job opening administration',
        'menubutton' => 'Job openings',
        'applicants' => 'Applicants: ',
        'viewapplicants' => 'View applicants',
        'title1033' => 'Title (English)',
        'title3084' => 'Title (French)',
        'desc1033' => 'Description (English)',
        'desc3084' => 'Description (French)',
        'invalidid' => 'Invalid identifier, you cannot fix this error unless you reload and page and lose changes',
        'invalidtitle1033' => 'Invalid english title, must contain between 1 and 100 characters',
        'invalidtitle3084' => 'Invalid french title, must contain between 1 and 100 characters',
        'invaliddesc1033' => 'Invalid english description',
        'invaliddesc3084' => 'Invalid french description',
        'invalidfirstname' => 'You must enter your first name, must contain between 1 and 50 characters',
        'invalidlastname' => 'You must enter your last name, must contain between 1 and 50 characters',
        'invalidfile' => 'The file sent is invalid, if only PDF or DOC are accepted',
        'invalidtelephones' => 'At least one of the phone numbers must be provided, must contain between 1 and 20 characters',
        'appliedon' => ' applied on  ',
        'cellphone' => 'Telephone (Cell.): ',
        'telephone' => 'Telephone (Home): ',
        'email' => 'E-Mail: ',
        'comment' => 'Comment: ', 
        'viewattachment' => 'Show attached CV',
        'attachment' => 'Curriculum Vitae: ',
        'firstname' => 'First name: ',
        'lastname' => 'Last name: ',
        'apply' => 'Apply for this position',
        'applicationsaved' => 'You application has been saved. Please take note that only selected candidates will receive a callback.',
        'notessaved' => 'Notes for the following application where saved: ',
        'errorsavingnotes' => 'An unexpected error occured while saving the notes, this note was not saved: ',
        'cvtype1' => 'Fill out an online job application form',
        'cvtype2' => 'Send my own CV',
        'cvtype3' => 'Do not attach any CV',
        'cvnote' => 'You will be able to fill the online job application form after clicking on the "Submit" button.',
        
        'infolabel' => 'Personal informations',
        'firstname' =>  'First name',
        'lastname' =>  'Last name',
        'address' =>  'Address',
        'city' =>  'City',
        'region' =>  'Province',
        'postalcode' =>  'Postal code',
        'email' =>  'E-Mail',
        'tel1' =>  'Telephone 1',
        'tel2' =>  'Telephone 2',
        'drivingclass' =>  'Driving permit class',
        'displabel' => 'Availabilities',
        'hasnaslabel' => 'I\'m allowed to work in canada?',
        'hasnas' =>  'Yes, i have a social security number (SSN)',
        'languageslabel' => 'Languages',
        'haswritten' =>  'I write',
        'hasspoken' =>  'I speak',
        'availabilitieslabel' => 'Availabilities',
        'canpermanent' =>  'I\'m expecting a full-time job',
        'canparttime' =>  'I\'m expecting a part-time job',
        'canstudent' =>  'I\'m expecting a summer job',
        'disp' =>  'I will be available from ',
        'dispovertime' =>  'I\'m available to do overtime',
        'dispsaturday' =>  'I\'m available to work week-ends',
        'schoolinfo' => 'School information (From latest to oldest)',
        'schoolinst' =>  'Institution',
        'schooltype' =>  'Orientation',
        'schoolfrom' =>  'From',
        'schoolto' =>  'To',
        'schooldiploma' =>  'Diploma',
        'jobinfo' => 'Work experience (From latest to oldest)',
        'jobname' =>  'Company',
        'jobtel' =>  'Telephone',
        'jobfunc' =>  'Function',
        'jobfrom' =>  'From',
        'jobto' =>  'To',
        'abilitieslabel' => 'Certifications and abilities',
        'hasoffice' => 'Office software',
        'hasword' => 'I can use MS Office Word (or an equivalent)',
        'hasexcel' => 'I can use MS Office Excel (or an equivalent)',
        'hasaccess' => 'I can use MS Office Access (or an equivalent)',
        'hasother' => 'Other software: ',
        'hascert' => 'Certifications', 
        'certlift' => 'Lift',
        'certbridgecrane' => 'Bridge crane',
        'certhealth' => 'Health and safety',
        'certother' => 'Other certification : ',
        'certabilities' =>  'Particular abilities (Precise)',
        'invalidaddress' => 'Invalid address, must contain between 1 and 250 characters',
        'invalidcity' => 'Invalid city, must contain between 1 and 100 characters',
        'invalidregion' => 'Invalid province, must contain between 1 and 100 characters',
        'invalidpostalcode' => 'Invalid postal code, must contain between 1 and 10 characters',
        'alreadydone' => 'You have already submitted your CV for this job opening, it is not possible to change or start over, please apply again',
        'invaliddisp' => 'Invalid availability date, must respect the YYYY-MM-DD format',
        'invalidform1from' => 'Invalid "From" date at school experience #1, must respect the YYYY-MM format',
        'invalidform2from' => 'Invalid "From" date at school experience #2, must respect the YYYY-MM format',
        'invalidform3from' => 'Invalid "From" date at school experience #3, must respect the YYYY-MM format',
        'invalidform1to' => 'Invalid "To" date at school experience #1, must respect the YYYY-MM format',
        'invalidform2to' => 'Invalid "To" date at school experience #2, must respect the YYYY-MM format',
        'invalidform3to' => 'Invalid "To" date at school experience #3, must respect the YYYY-MM format',
        'invalidjob1from' => 'Invalid "From" date at work experience #1, must respect the YYYY-MM format',
        'invalidjob2from' => 'Invalid "From" date at work experience #2, must respect the YYYY-MM format',
        'invalidjob3from' => 'Invalid "From" date at work experience #3, must respect the YYYY-MM format',
        'invalidjob1to' => 'Invalid "To" date at work experience #1, must respect the YYYY-MM format',
        'invalidjob2to' => 'Invalid "To" date at work experience #2, must respect the YYYY-MM format',
        'invalidjob3to' => 'Invalid "To" date at work experience #3, must respect the YYYY-MM format',
        'viewcvattachment' => 'Show attached CV',
    ),
);
?>
 
And the code to load a locale file is the following:

Code: Select all

 
<?php
//Start the session
session_start();
 
//Validate the locale and load it
$validlocales = array(3084, 1033);
if(isset($_SESSION['locale']) && !in_array($_SESSION['locale'], $validlocales)){
    $_SESSION['locale'] = $validlocales[0];
}elseif(!isset($_SESSION['locale'])){
    $_SESSION['locale'] = $validlocales[0];
}
 
//Check if locale change requested
if(isset($_GET['locale']) && in_array($_GET['locale'], $validlocales)){
    $_SESSION['locale'] = $_GET['locale'];
}
 
//Locale can also be detected via path, check if english or francais can be found in request
if(strpos($_SERVER['REQUEST_URI'], '/english/') !== false){
    $_SESSION['locale'] = 1033;
}elseif(strpos($_SERVER['REQUEST_URI'], '/francais/')){
    $_SESSION['locale'] = 3084;
}
 
//Load the locale
include('../assets/locale/'.$_SESSION['locale'].'.php');
 
//Setup alternate locale
$alternatelocale = ($_SESSION['locale'] == 1033 ? 3084 : 1033);
?>
 
This previous code i usually put it in my system.php file that i include on each page i work with...

The errors that gets pushed in the $errors array come from the $strings array defined in the locale file. And the errors are detected in the post using various validation techniques such as:

Code: Select all

 
        //Analyse the posted information for errors
        if(!isset($_POST['applicantid']) || !is_numeric($_POST['applicantid'])){ $errors[] = $strings['adminrh']['invalidid'].' (1)'; }
        if(!isset($_POST['happlicantid']) || !is_string($_POST['happlicantid'])){ $errors[] = $strings['adminrh']['invalidid'].' (2)'; }
        if(!isset($_POST['firstname']) || !is_string($_POST['firstname']) || strlen($_POST['firstname']) < 1 || strlen($_POST['firstname']) > 50){ $errors[] = $strings['adminrh']['invalidfirstname']; }
        if(!isset($_POST['lastname']) || !is_string($_POST['lastname']) || strlen($_POST['lastname']) < 1 || strlen($_POST['lastname']) > 50){ $errors[] = $strings['adminrh']['invalidlastname']; }
        if(!isset($_POST['address']) || !is_string($_POST['address']) || strlen($_POST['address']) < 1 || strlen($_POST['address']) > 250){ $errors[] = $strings['adminrh']['invalidaddress']; }
        if(!isset($_POST['city']) || !is_string($_POST['city']) || strlen($_POST['city']) < 1 || strlen($_POST['city']) > 100){ $errors[] = $strings['adminrh']['invalidcity']; }
        if(!isset($_POST['region']) || !is_string($_POST['region']) || strlen($_POST['region']) < 1 || strlen($_POST['region']) > 100){ $errors[] = $strings['adminrh']['invalidregion']; }
        if(!isset($_POST['postalcode']) || !is_string($_POST['postalcode']) || strlen($_POST['postalcode']) < 1 || strlen($_POST['postalcode']) > 10){ $errors[] = $strings['adminrh']['invalidpostalcode']; }
        if(!isset($_POST['tel1']) || !is_string($_POST['tel1']) || strlen($_POST['tel1']) < 1 || strlen($_POST['tel1']) > 20){ $tel1invalid = true; }
        if(!isset($_POST['tel2']) || !is_string($_POST['tel2']) || strlen($_POST['tel2']) < 1 || strlen($_POST['tel2']) > 20){ $tel2invalid = true; }
        
        //Analyse the dates if posted, no date is required, but if posted, it must have a correct format
        if(isset($_POST['disp']) && !empty($_POST['disp']) && datefrom($_POST['disp'], 1970, 1, 1, true, true, true) == false){ $errors[] = $strings['adminrh']['invaliddisp']; }
        if(isset($_POST['form1from']) && !empty($_POST['form1from']) && datefrom($_POST['form1from'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidform1from']; }
        if(isset($_POST['form2from']) && !empty($_POST['form2from']) && datefrom($_POST['form2from'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidform2from']; }
        if(isset($_POST['form3from']) && !empty($_POST['form3from']) && datefrom($_POST['form3from'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidform3from']; }
        if(isset($_POST['form1to']) && !empty($_POST['form1to']) && datefrom($_POST['form1to'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidform1to']; }
        if(isset($_POST['form2to']) && !empty($_POST['form2to']) && datefrom($_POST['form2to'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidform2to']; }
        if(isset($_POST['form3to']) && !empty($_POST['form3to']) && datefrom($_POST['form3to'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidform3to']; }
        if(isset($_POST['job1from']) && !empty($_POST['job1from']) && datefrom($_POST['job1from'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidjob1from']; }
        if(isset($_POST['job2from']) && !empty($_POST['job2from']) && datefrom($_POST['job2from'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidjob2from']; }
        if(isset($_POST['job3from']) && !empty($_POST['job3from']) && datefrom($_POST['job3from'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidjob3from']; }
        if(isset($_POST['job1to']) && !empty($_POST['job1to']) && datefrom($_POST['job1to'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidjob1to']; }
        if(isset($_POST['job2to']) && !empty($_POST['job2to']) && datefrom($_POST['job2to'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidjob2to']; }
        if(isset($_POST['job3to']) && !empty($_POST['job3to']) && datefrom($_POST['job3to'], 1970, 1, 1, true, true, false) == false){ $errors[] = $strings['adminrh']['invalidjob3to']; }
 
Then, if there are errors in the $errors array, i simply do not process the mysql part and continue down the HTML portion and then i hit the section where it checks count($errors) and then displays the errors in the $errors array using implode().

Is that more clear?

Re: redirect unsets session variables

Posted: Mon May 18, 2009 8:40 am
by lubber123
Yes, this is great. Much simpler way of doing it than I the way i was doing it. Excellent. Thanks for all your help.

Re: redirect unsets session variables

Posted: Mon May 18, 2009 9:54 am
by mattpointblank
Not sure if you'll still find this useful, but I had this problem and fixed it with this code:

Code: Select all

 
 $_SESSION['variable'] = "something";
session_write_close(); // fixes this bug
header("Location: somewhere.php"); // send them somewhere else
exit(); // stop processing stuff