Welcome Guest, Not a member yet? Register   Sign In
Pulling data from form_validation in controller
#1

[eluser]bluematt[/eluser]
I've recently downloaded the 1.7 release to port an app, and I may be being completely dense, but I don't seem to be able to get form data (after being filtered through the form_validation library, hopefully with appropriate data prepping) into the controller.

The
Code:
set_value()
function works fine for the view, but what function/array/variable should I be using to get it into the controller?

e.g.

Code:
class Test extends Controller {
  
  function Test()
  {
    parent::Controller();
  }
  
  function index()
  {
    $this->load->library('form_validation');
    $this->form_validation->set_rules('hash', 'Item to be hashed', 'required|md5');
    
    if ($this->form_validation->run()) {
      $data['hash'] = $_FORM['hash']; // <--  What should I use here to use the
                                      //      form_validation prepped value?
    }
    
  }
  
}

I've scoured the docs, the forums and the library itself to no avail. Have I missed something incredibly obvious?

TIA for any help.
#2

[eluser]Randy Casburn[/eluser]
Hi bluematt,

Welcome to CodeIgniter!

It isn't clear, but you can always use the Input class. Once your data us run through Validation has been cleaned. So you can do this:

$this->input->post('some_data');

to gain access to it.

Hope this is helpful.

Randy
#3

[eluser]bluematt[/eluser]
Thanks for the feedback. Yes, I'd already tried the $this->input->post(), but this doesn't reflect the prepped version of the data, only the raw data from $_POST (presumably after having gone through the XSS filter). I'm happy to use the encrypt() function afterwards on the raw $input->post(), but I thought the point of the data prepping in the form_validation was to remove such things.

Oh well, thank again.
#4

[eluser]Pascal Kriete[/eluser]
You have to set_fields for the changes to be applied to the $_POST array. $this->input->post() and $_POST are identical.
[EDIT: crap, nvm - that was the old one]
#5

[eluser]Helmi_xisnet[/eluser]
Hi all, is there any concrete solution to this. I'm also wondering how to get the post-validation data inside a controller

Edit: found a solution here: http://ellislab.com/forums/viewthread/95074/
which in fact is the same as above.




Theme © iAndrew 2016 - Forum software by © MyBB