What a good way to handle email data in Codeigniter?

those. would you advise me to use one controller method as follows:

function save() { if(!is_bool($this->input->post(''))) { $post_data = $this->input->post(''); $this->mymodel->save($post_data); } $this->load->view('myview'); } 

Or could you write it using two methods?

 function save() { if(!is_bool($this->input->post(''))) { $post_data = $this->input->post(''); $this->mymodel->save($post_data); } redirect('controller/method2') } 

A redirect is a crucial difference. It prohibits the resubmission of updates, for example.

How do you do this? Is there any better way?

+4
source share
3 answers

You should always redirect the deleted form message.

+11
source

You should always redirect the deleted form message.

That's right. For someone wondering why this is, here are a couple of reasons:

  • Avoid "repeated submissions . " Has it ever been when you innocently clicked the Refresh button or hit the Back and wham buttons, was everything resent?
  • Bookmark friendly . If your user has bookmarks on the page, perhaps you want them to go back to where they created it, and not an empty form (redirection makes them bookmarks on the confirmation / destination page.

Further reading: http://en.wikipedia.org/wiki/Post/Redirect/Get

+8
source

As Aren B said, redirecting is a good idea, but what I would change in your code is that mail validation should be done using the form validation function. This is not only more relevant, but the code will be shorter.

If you want to handle AJAX requests, you will need to return something other than through or through a redirect.

+3
source

Source: https://habr.com/ru/post/1316683/


All Articles