Welcome Guest, Not a member yet? Register   Sign In
validation and data afterwards
#1

[eluser]soupdragon[/eluser]
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

thanks
#2

[eluser]Hyra[/eluser]
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.
#3

[eluser]soupdragon[/eluser]
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) :-)
#4

[eluser]Hyra[/eluser]
Ah

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

Pseudo code:

Code:
function index() {
   // show form
   $this->load->view("form.html");
}

function process() {
    // Get the posted stuff and do something
    // Use validation library
    
    // If everything is okay:
    $this->redirect("/form/success");
}

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).
#5

[eluser]soupdragon[/eluser]
perfect thats what i was trying to get my head round :-)
#6

[eluser]xwero[/eluser]
That's why Hyra called it pseudo code i guess Smile
#7

[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?
#8

[eluser]Hyra[/eluser]
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
#9

[eluser]soupdragon[/eluser]
lol sorry i worked out that redirect worked whereas $this->redirect didn't

so kicked it back out !




Theme © iAndrew 2016 - Forum software by © MyBB