[eluser]Marcone Ramos[/eluser]
I am following a tutorial about creating a simple login form. All I know is that nothing happens when I submit the form. It loads the same page, like the submit had no effect.
Can you guys help me please? I just can't see what's wrong.
the controller:
Code:
class C_loginsyslogin extends CI_Controller{
//creating the index, the default function in my class
function index() {
//Load Libraries
$this->load->library(array('encrypt', 'form_validation', 'session'));
// LOAD HELPERS
$this->load->helper(array('form', 'url'));
// VALID USER CREDENTIALS
$user_credentials = array();
$user_credentials['testuser1'] = array(
'user_name' => 'testuser1',
'user_pass' => 'Gag/R6LlMz8JKhjd+pkMrL+MUIHn86vjs/ZJ31uH+QRCh1eRxxA0Fve6FXfE7rmFqgqsiwe2ZFrFT8ylZs050A==' // password
);
$user_credentials['testuser2'] = array(
'user_name' => 'testuser2',
'user_pass' => 'Gag/R6LlMz8JKhjd+pkMrL+MUIHn86vjs/ZJ31uH+QRCh1eRxxA0Fve6FXfE7rmFqgqsiwe2ZFrFT8ylZs050A==' // password
);
$user_credentials['testuser3'] = array(
'user_name' => 'testuser3',
'user_pass' => 'Gag/R6LlMz8JKhjd+pkMrL+MUIHn86vjs/ZJ31uH+QRCh1eRxxA0Fve6FXfE7rmFqgqsiwe2ZFrFT8ylZs050A==' // password
);
//---------------- SUBMISSION --------------------
//set_rules(THE NAME OF THE FIELD, THE NAME THAT USER SHOULD SEE THEM, IF IT'S REQUIRED OR NOT);
$this->form_validation->set_rules('txtusername','User Name','required');
$this->form_validation->set_rules('txtpassword','Password','required');
//--------------- VALIDATING --------------------
// has the form been submitted and with valid form info (not empty values)
if($this->input->post('bntEnter'))
{
echo 'para';
exit;
if($this->form_validation->run())
{
$user_name = $this->input->post('txtusername');
$user_pass = $this->input->post('txtpassword');
if(array_key_exists($user_name, $user_credentials))
{
// continue processing form (validate password)
}
else
{
$this->session->set_flashdata('message', 'A user does not exist for the username specified.');
redirect('c_/index/');
}
}
}
//-----------------END VALIDATING ---------------
//----------------- END SUBMISSION ------------
$loadTemp["varContent"]="v_loginsyslogin";
$this->load->view('v_admintemplate', $loadTemp);
}
}
the view file
Code:
<?php if($this->session->flashdata('message')) : ?>
<p><?=$this->session->flashdata('message')?></p>
<?php endif; ?>
<? $attributes=array('name' => 'formLogin','class' => 'formLogin', 'enctype' => 'application/x-www-form-urlencoded'); ?>
<?=form_open('c_loginsyslogin/index/', $attributes)?>
<p>Por favor, identifique-se:</p>
<p>
<?=form_label('Login:', 'user_name')?>
<?
//echo form_error("txtusername");
$formBuildingData= array(
'type' => "text",
'name' => "txtusername",
'class' => "normalText",
'size' => "25"
);
?>
<?=form_input($formBuildingData)?>
</p>
<p>
<?=form_label('Senha:', 'user_pass')?>
<?
//echo form_error("txtpasswordd");
$formBuildingData2= array(
'type' => "password",
'name'=> "txtpassword",
'class' => "normalText",
'size' => "25"
);
?>
<?=form_password($formBuildingData2)?>
</p>
<p>
<?
$formBuildingData3=array(
'type' => "submit",
'name' => "bntEnter",
'class'=> "buttonNormal",
'value'=> "Entrar"
);
?>
<?=form_submit($formBuildingData3)?>
</p>
<?=form_close();?>
config
Code:
$config['index_page'] = 'index.php';