[eluser]Alfredo Palhares[/eluser]
Hello, i am first time trying the Code Igniter Framework.
I am using the rules in for for validation in an array i followed the rules in this link:
Setting the rules in an array
Then i have the need to set more rules in one fiels and i set the rules like in here;
Cascading Rules
My code is show here
Code:
function register()
{
//Chamar os helpers e as librarias
$this->load->helper(array('form','url'));
$this->load->library('form_validation');
//Definir as regras dos campos
// Atenção o nome do array tem que ser config
$config = array(
array(
'field' => 'username',
'label' => 'Nome de Utilizador',
'rules' => 'required'),
array (
'filed' => 'password',
'label' => 'Password',
'rules' => 'required'),
array (
'field' => 'passwordconfirm',
'label' => 'Confirmação da Password',
'rules' => 'trim|required|matches[password]'),
array(
'field' => 'email',
'label' => 'Endereço de Email',
'rules' => 'required|valid_email'),
array(
'field' => 'emailconfirm',
'label' => 'Confirmação do endereço de email',
'rules' => 'required|matches[email]|valid_email')
);
$this->form_validation->set_rules($config);
//Definir a messagem de erros
$this->form_validation->set_message('required', 'O campo %s apresenta um preenchimento incorrecto');
//Correr a validação
if ($this->form_validation->run() == false) {
$this->load->view('forms/user_register.php');
}
else {
$this->load->view('forms/user_register_success');
}
//TODO: Chamar a verfifocação de dados
//TODO: Introduzir os dados na base de dados
}
Here is my view file too:
Code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Registar</title>
</head>
<body>
<?php echo validation_errors(); //Erros de validação ?>
<?php echo form_open('user/register'); //Gera o form helper open header ?>
Nome de utilizador: <br />
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50"> <br />
Passowrd: <br />
<input type="paswword" name="password" value="<?php echo set_value('password'); ?>" size="50"> <br />
Confirme Password: <br />
<input type="paswword" name="passwordconfirm" value="<?php echo set_value('passwordconfirm'); ?>" size ="50"><br />
Endereço de e-email:<br />
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50"><br />
Confirmação de e-mail:<br />
<input type="text" name="emailconfirm" value="<?php echo set_value('emailconfirm'); ?>" size= "50"><br />
<!-- Esta div separada serve para ter o butão "afastado" do restante-->
<div id="submit">
<input type="submit" name="submit" value="Submit"> <br />
</div>
</form>
</body>
</html>
THE PROBLEM:The rules except the "required" isn't working, i tried to introduce an invalid email, a different passwords, and the form was accepted.
I am not very experienced in PHP (only about 3 months of programing) but i read the documentation and i didn't found any error. please correct me.
Thanks anyway