I always use the Post/Redirect/Get method on my forms. My forms generally always submit to themselves. However, when I have an error in the form, I don't send any new headers. This is so I can easily do stuff like this
<input type="text" name="email" value="<?php echo $this->input->post('email', '') ?>" />
The PHP is just a library function that handles 2 arguments, the $_POST key and a default value if it isn't present.
This means if someone makes an error in the form, they don't have to refill out the form a second time. The disadvantage is that reloading the page gives them the POST warning in their browser.
Is there anyway to avoid this, without using something for state (i.e. cookies, session, database etc)
I find the best way to do this is use the header function. You can post to what ever file you need even itself do the validation then use the header redirect to go back to the form if it failed. Store the post'd values in the session or another accessible variable, therefore you can access the previously entered data.
When using header("location: myscript.php"); make sure to include an exit(); afterwards otherwise you will still get the POST warning on a refresh.
myscript.php
if($_POST['submit'])
{
//check for errrors
if ($error)
{
$_SESSION['myPostVars'] = $_POST;
header("location: myscript.php");
exit();
}
}
<form>
// your form code
</form>
Edit: I just noticed that you edited your question to avoid using sessions.
You could serialize the post vars you want to return and put them in the query string (sent via the header()