Welcome Guest, Not a member yet? Register   Sign In
how to get data from the form
#1

[eluser]pshah.mumbai[/eluser]
I have setup the validation and everything and I need to enter the data into the database.

how do i get the data from the FORM fields ?

$_POST/$_GET ?

What is the name of the array that has the data from the form field

eg : post['username'] ??
#2

[eluser]ejangi[/eluser]
Check out the input/security class:
Code:
$username = $this->input->post('username');
#3

[eluser]coolfactor[/eluser]
You can *always* use standard PHP within CodeIgniter, but ucantblamem pointed you to the "CodeIgniter way" of doing it, which offers some protection against values that might not exist in the form data.
#4

[eluser]pshah.mumbai[/eluser]
thanks guys !
#5

[eluser]Colin Williams[/eluser]
The best way, IMO, is to use the Validation class. The Validation class is namespaced in such a way that it allows for all your defined fields to become properties of the validation object ($CI->validation). The bonus here is that these properties are "cleaned" in the validation process if you use available or custom validation rules.

Take this bit of a controller for example:
Code:
function capture(){
  $this->load->library('validation');
  $rules = array(
    'name' => 'required|trim',
    'phone' => 'required|callback__phone_clean',
  );
  $this->validation->set_rules($rules);
  $fields= array(
    'name' => 'Name',
    'phone' => 'Phone Number',
  );
  $this->validation->set_fields($fields);
  if ($this->validation->run()) {
    // Pretend '(555) 122-5889' was entered for 'phone' field
    print $this->validation->phone;
    // Prints 5551225889
    // Additionally, $this->validation->name would have been trimmed
  }
}
function _phone_clean($phone) {
  // We can access and modify the validation property for this field!
  $this->validation->phone = preg_replace('/[^0-9]/', '', $this->validation->phone);
  return TRUE;
}




Theme © iAndrew 2016 - Forum software by © MyBB