CodeIgniter Forums

Full Version: validation and data afterwards
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

A quick question
I'm doing some validation in my controller works perfectly, so if all
okay go to my model and insert all into my db - also works.
they then get redirected to the next sucess page.

My question is er...are

1. How / where should i reset the _POST data
2. How to avoid when refresh pressed the data being inserted again? (as opposed to just checking in the db if already inserted)
3. Anyway to make the back button go elsewhere eg.over a header redirect

Not sure if that lot is clear ...when not shout


El Forum

As for number 2:

If you indeed redirect (header: location) to a success-page, refreshing that page won't resubmit the form data, as it's static.

For number 3 (which would make solving point 1 unnecessary), there is no real way to do this.

What you could do is use sessions, and set a session var when the form is submitted. Then check that session var to see if the form has already been submitted. Maybe use timestamps to prevent resubmitting for 5 minutes.

El Forum

with my redirect after the insert - i am using in my controller goto new view
$this->load->view('seller_start', $data);

how do i use that then to do a header redirect ?
(outside of codeigniter would be no problem but i am trying to learn follow CI) :-)

El Forum


well you could do something like this in your controller "form.php"

Pseudo code:

function index() {
   // show form

function process() {
    // Get the posted stuff and do something
    // Use validation library
    // If everything is okay:

function success() {
     $this->load->view("form_success.html", $data);

By redirecting the user to a thank you page they can refresh that page but it will still only call /form/success/ so no data is being reprocessed. You can fill /form/process/ with whatever is needed to do with the received data.

If you hit the Back button from the success-page it should go to the form page (/form/index/) as it skips the header redirect which didnt produce any cachable data as you didn't output anything.

Hope this helps (and makes sense).

El Forum

perfect thats what i was trying to get my head round :-)

El Forum

That's why Hyra called it pseudo code i guess Smile

El Forum

[eluser]Michael Wales[/eluser]
redirect() is a function within the URL helper.

Helpers are not object oriented pieces of the framework, therefore using them within an OO reference would not work. Basically, there is no redirect function for that specific class (as helper functions are not loaded into any class).

EDIT: WTF, where did the question regarding redirect() vs. $this->redirect() go?

El Forum

I guess i missed both the removed post and therefore the sense of the response.

But yes, it was meant to be a guiding/pseudo code written in 3 seconds and therefore won't work "as is" Tongue

El Forum

lol sorry i worked out that redirect worked whereas $this->redirect didn't

so kicked it back out !