If you have the validation in a different file then you could utilise sessions to set whatever data you wanted and redirect the user back to the form page.
session_start(); //this need to be at the top of each page you're wishing to use sessions on
$validationObject = (object) array(
'validationError' => false;
);
$username = $_POST['username'];
//run your validation here, I've done one as an example
if (empty($username)) {
$validationObject->validationError = true;
$validationObject->username = (object) array(
'message' => 'User name is required',
'value' => $username
);
//I know setting the value here seems like a waste of time but if you were validating an email then you'd want to return the attempt to the user
}
//before the logic for processing the form, here we're just checking for errors
if ($validationObject->validationError) {
$_SESSION['validation'] = $validationObject;
header('Location: whateverPageYourFormIs.php');
die();
}
//process the form
//html starts here
Then for your form page:
<?php
session_start();
if (isset($_SESSION['validation']) && $_SESSION['validation']->validationError) {
$validationObject = $_SESSION['validation'];
//unset the validation object so it's not used more than once
unset($_SESSION['validation']);
}
?>
<!-- HTML header here -->
<form method="POST" action="submit.php">
<fieldset>
<label>Username</label>
<div class="form-group">
<input name="username" class="span-default" type="text" placeholder="Choose a username" value="<?php echo (isset($validationObject, $validationObject->username)) ? $validationObject->username->value : ''; ?>">
<?php
if (isset($validationObject, $validationObject->username)) {
?>
<div class="form-warning"><?php echo $validationObject->username->message; ?></div>
<?php
}
?>
</div>
</fieldset>
</form>
I haven't tested this so it might have a few errors, but I'm sure it'll point you in the right direction. It's not complicated and uses stdClass objects. You could create a validation wrapper which may make things a little neater.
Hope it help anyway, any problems then give us a shout