Codeigniter: passing form data from a view to a controller

What is right? notification in the second option, I pass the values โ€‹โ€‹of the form using the variable $ _POST. While the first option, I call and assign variables to each form field.

I have seen that...

<validation code> ....

$todo = array(
      'name'=>$this->input->post('title'),
      'description'=>$this->input->post('description')
);

$this->Todo_model->add($todo); 

But I also saw the following ...

$records['email']    = "trim|required|min_length[4]|xss_clean";
...
...    

$this->validation->set_rules($records);

if ($this->validation->run())
{
   $this->account_model->saveAccountSettings("sam", $_POST);
   $this->session->set_flashdata('message', 'Done!');            

   redirect('account/settings');
} else {
...
} 
+3
source share
3 answers

I try to use a combination of your two examples. I'm pretty sure things like trim won't change the actual data, so you can only use them if you go through a validation system to get the data. In fact, I never use POST again using CI.

, POST . , - " " , db ? , , . , .

.

:

$fields['email']    = "trim|required|valid_email|min_length[4]|xss_clean";
...
...    

$this->validation->set_rules($fields);

if ($this->validation->run())
{
   $account = new array();
   $account['id'] = $accountId; //wherever you get the Id from
   $account['email'] = $this->validation->email;

   $this->account_model->save($account);
   $this->session->set_flashdata('message', 'Done!');            

   redirect('account/settings');
} else {
...
} 
+3

Pass -

0

$account['email'] = $this->validation->email;

$account['email'] = $this->input->post('email');
0

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


All Articles