Welcome Guest, Not a member yet? Register   Sign In
$_POST and $this->input->post() are always empty on localhost site
#13

[eluser]osci[/eluser]
The first time the method login is called it has no post values if you are talking about before submitting.

If I am redirected from another controller because / method because I was denied wouldn't I have empty values also?

Ian I read your code once more and have other issues to point out.

The way you code you make a $user->data array and then pass it to the view. Why's that? For passing values if validation process fails? If so for a start you should do in your array constructor
Code:
'email' => ($this->input->post('email')? $this->input->post('email') : '';
because input->post() returns false if the var is not set.

If I'm redirected from another site you would create a session var for a 404 page maybe?

Code:
if ($this->form_validation->run() or $this->ion_auth->logged_in())
Why is that combined?
Put the check for logged_in in the start of your login function.
So no need for the validation code (validation). You'll put your redirect code in the if logged_in and redirect accordingly.

Why not use your view without passing that array and use set_value from form_helper?
You would just have
Code:
<input type="text" name="email" maxlength="120" value="<?php echo set_value('email'); ?>" />
//where email is the name of the input field
and eliminate the need of your user_data array.

Also as I proposed you would put all (EDIT:almost) your code except the view rendering part in
Code:
if ($this->input->post('btnLogin'))
{
//all your code except the "Render the view" part
}

so your code would be like
Code:
if ($this->ion_auth->logged_in())
{
   // do your redirects
   // redirectto is set by another method or controller where access is denied
   // so you will not manipulate this session

   $redirectto = (strlen($this->session->userdata('redirect_to'))>0) ?
           $this->session->userdata('redirect_to') :
           '/'; //Your default redirect here
   $this->session->unset_userdata('redirect_to');
  
   redirect($redirect_to);
}

if ($this->form_validation->run())
{
   //check for validation with ion auth
   //Dont know but something like
   if ($this->ion_auth->checklogin($this->input->post('email'),
               $this->input->post('password')))
   {
      //same code as above
      //EDIT set your required session vars here
      $this->session->set_userdata('name', $this->input->post('email'));
      //now redirect
      $redirectto = (strlen($this->session->userdata('redirect_to'))>0) ?
           $this->session->userdata('redirect_to') :
           '/'; //Your default redirect here
      $this->session->unset_userdata('redirect_to');
  
      redirect($redirect_to);
   }
}

//since we are here either we have failed in validation or we just arrived
//show view
$this->data->sBodyClass = 'one-col';
$this->template->build('login', $this->data);

I didn't take into account your hook since I don't know what it's doing but I guess it's not a problem.


EDIT:
I noticed you do form_open('/users/login');
remove the first slash.


Messages In This Thread
$_POST and $this->input->post() are always empty on localhost site - by El Forum - 06-21-2011, 11:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB