Reputation: 189
I have tried many google hits but I am yet unable to retrieve any POST data from forms, $_POST is just an empty array array(0) { }
. I found few posts which was saying that problem is in .htaccess which doesn't correctly redirect my POST data but any of those posts didn't help me. I have tried many .htaccess files I found but none of them worked with POST data.
I am using Debian Jessie with Apache 2.4.10, PHP 5.6.14-0+deb8u1. I have AllowOverride all
inside <Directory
at my VHOST file. CodeIgniter 3.0.3. I have var_dump($_POST);
at top of the index.php for testing. I also have enabled rewrite_module
. There are no errors in the apache2 error.log file.
Here is my setup:
Controller: Admin.php
<?php
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->library('session');
$this->load->library('form_validation');
}
public function index()
{
if(isset($this->session->userdata['logged']))
{
$this->load->view('admin/dashboard');
}
else
{
$this->load->view('templates/default/header');
$this->load->view('admin_login');
$this->load->view('templates/default/footer');
}
}
public function login()
{
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() == FALSE)
{
echo "Validation failed!";
}
else
{
echo "Validation success!";
}
}
}
View: admin_login.php:
<form class="form-signin" method="post" action="/admin/login/">
<h2 class="form-signin-heading">Kirjaudu sisään</h2>
<label for="inputEmail" class="sr-only">Sähköpostiosoite</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Sähköpostiosoite" required autofocus>
<label for="inputPassword" class="sr-only">Salasana</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Salasana" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Muista minut
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Kirjaudu</button>
Current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Upvotes: 1
Views: 737
Reputation: 38609
Your action is wrong. It should come like this
action="<?php echo base_url()?>admin/login/">
as well as load url in helpers
$this->load->helper('form','url');
as well as in these input tags there is no name attribute
<input type="email" id="inputEmail" class="form-control" placeholder="Sähköpostiosoite" required autofocus>
<input type="password" id="inputPassword" class="form-control" placeholder="Salasana" required>
Do like this
In controller
$this->load->helper('form'); #load library
In view
<?
$attributes = array('class' => 'form-signin');
echo form_open('admin/login/', $attributes);
$data1 = array(
'id' => 'inputEmail',
'class' => 'form-control',
'Placeholder' => 'Sähköpostiosoite',
'name' => 'email',
);
echo form_input($data1);
$data2 = array(
'id' => 'inputPassword',
'class' => 'form-control',
'Placeholder' => 'Salasana',
'name' => 'password',
);
echo form_password($data2);
echo form_submit('submit', 'Log In');
echo form_close();
Upvotes: 1
Reputation: 247
Try this:
In controller add $this->load->helper(array('form','url'));
in function __construct()
In View:
<form class="form-signin" method="post" action="<?php echo base_url()?>admin/login">
<h2 class="form-signin-heading">Kirjaudu sisään</h2>
<label for="inputEmail" class="sr-only">Sähköpostiosoite</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Sähköpostiosoite" required autofocus>
<label for="inputPassword" class="sr-only">Salasana</label>
<input type="password" name = "password" id="inputPassword" class="form-control" placeholder="Salasana" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Muista minut
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Kirjaudu</button>
Hope this help! ^^
Upvotes: 1