• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validation and data afterwards

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


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.

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) :-)


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

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

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

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

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

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

so kicked it back out !

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.