i cannot get the post value from the form it inserting empty values in database
user controller
public function edit($id = NULL) {
if ($id) {
$this->data ['user'] = $this->user_login_model->get($id);
count ( $this->data ['user'] ) or $this->data ['errors'] [] = "user could not be found";
} else {
$this->data ['user'] = $this->user_login_model->new_user ();
}
$rules = $this->user_login_model->rules_admin;
$id || $rules ['password'] .= '|required';
$this->form_validation->set_rules ( $rules );
if ($this->form_validation->run () == TRUE) {
$data=$this->user_login_model->array_from_post(array('name','email','password'));
$this->data['password']=$this->user_login_model->$data['password'];
$this->user_login_model->save($data,$id);
redirect('admin/users');
// do stuff
}
if it's a new user then it will post new data
public function new_user() {
$user=new stdClass();
$user->name ='';
$user->email ='';
$user->password ='';
return $user;
var_dump($user);
model method which will loop through the array and return it
public function array_from_post($fields) {
$data = array ();
foreach ( $fields as $field ) {
$data['feild']=$this->input->post($field);
return $data;
echo var_dump($data);
}
}
this is the var_dump
object(stdClass)[22]
public 'id' => string '18' (length=2)
public 'email' => string '' (length=0)
public 'password' => string '' (length=0)
public 'name' => string '12' (length=2)
this is empty , can you tell me what is the problem ?
$data['feild']=$this->input->post($field);
This should be $data[$feild]=$this->input->post($field); – Shaiful Islam$data[$field]=$this->input->post($field);
besides of$data[$feild]=$this->input->post($field);
? – user1823693