CodeIgniter Forums
set_value or input->post - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: set_value or input->post (/showthread.php?tid=23726)



set_value or input->post - El Forum - 10-20-2009

[eluser]one4all[/eluser]
Hi all,

Someone could explain me the difference between Set_value('varname') or $this->input->post('varname') ? (if there is one...)

I mean after a success in a run validation, should we better use set_value (from form_valdation class) to retrieve data or $this->input->post (from input class) ? And why ?

Look at the 2 following examples

Ex1:
Code:
class Form extends Controller {
    
    function index()
    {
    
          $this->load->library('form_validation');
          $this->form_validation->set_rules('varname', 'varname', 'required|xss_clean');
  
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
              $mysafedata['varname']= set_value('varname');                      
              $this->load->view('formsuccess', $mysafedata[]);
        }
    }
}


Ex2:
Code:
class Form extends Controller {
    
    function index()
    {
    
          $this->load->library('form_validation');
          $this->form_validation->set_rules('varname', 'varname', 'required');
  
                
          if ($this->form_validation->run() == FALSE)
      {
         $this->load->view('myform');
          }
      else
      {
          $mysafedata['varname']= $this->input->post('varname', TRUE);            
      $this->load->view('formsuccess', $mysafedata[]);
      }
    }
}


So, in this exemple, better use Ex1 or Ex2 ? Why ?
And if Ex2, can someone give me example where "xss_clean" in validation rule could be interesting ?

Thanks a lot for lighting me,
One4all


set_value or input->post - El Forum - 10-20-2009

[eluser]pistolPete[/eluser]
set_value() is meant to be used in views only, I'd use $this->input->post() in the controllers.


set_value or input->post - El Forum - 10-21-2009

[eluser]one4all[/eluser]
Thanks for opinion.

I'm agree seems that set_value has to be used in "write" context...so better in view. And ->input->post in controller...

But as we have set the rule for each elem for a form for example, we have to do same things for input, and (for example) if you set xss_clean, you have to repeat this "treatment" 2 times, for the set_rule value and when you retrieve the input->post value...

Is there a way to optimize those actions ?...