Welcome Guest, Not a member yet? Register   Sign In
Changing URL after form submission
#1

[eluser]Andy UK[/eluser]
Hi guys,

I'm wondering how i can avoid a function being run multiple time by a user clicking reload. For example, i have a contact form at the url http://www.myexamplesite.com/contact which when submitted runs the function send via http://www.myexamplesite.com/contact/send.

All well and good. The form is submitted and, if everything is ok, a thankyou message is displayed. But now the url is still http://www.myexamplesite.com/contact/send and any reload by the user will send another copy of the form.

Is there a cleaner way to manage this? I'm thinking maybe a rewrite of the url or something. I'd rather not redirect after a given number of seconds as i don't want to lose the thankyou message or take control away from the user.

All ideas are gratefully received!

Andy.
#2

[eluser]Met[/eluser]
make a view called "thanks"

in your contact/send function, send the email as normal etc but rather than echo any output, do this:

Code:
//finish sending email
redirect('contact/thanks', 'location');


// and have a function called thanks in the contact constructor
function thanks()
{
    $this->load->view('templates/thanks');
}

so you send the email, then redirect the user away from the "send" function, and display the thank you page.
my CI knowledge is remarkably basic however so theres probably an alternative method...hope it helps
#3

[eluser]Andy UK[/eluser]
Thanks Met, looks like a nice easy solution. I'll give it a go and let you know. And if anyone else has a different way of doing it, it would be good to hear it also... If nothing else but to learn more techniques!




Theme © iAndrew 2016 - Forum software by © MyBB