In the CodeIgniter framework I have a form action that posts the id of a number of checkboxes to a controller. The controller checks each id to ensure it is valid, and then prints off a pdf document. This works fine.
So, my current method is /items, and I am posting to the /documents method
function documents()
if ($this->input->post() && validate_documents())
{
$this->load->library('Print_docs');
$this->print_docs->execute($this->input->post());
}
}
So, if the docs get printed, then this works fine: the user remains on the /items method and pdf is offered as a download in the browser.
If, however, validate_documents() is false, then I dont want anything to happen – i.e. the user should remain on the /items method. However, what is actually happening is that the user is somehow being redirected to the /documents method – and the browser is blank.
So, why is the user being redirected to the /documents method? And how do I keep the user on the /items method no matter what?
A form post is a page refresh. When the pdf is generated, the page “refresh” is actually you downloading the pdf – so the browser doesn’t take you away from the
/itemsmethod — it’s the same as if you open a link withtarget="_blank", the page is opened in a new window and the current page is untouched.You can do 1 of 2 things here:
documentsmethod back to/items/items