CodeIgniter Forums
Form Validation Rules - What i am doing wrong? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Form Validation Rules - What i am doing wrong? (/thread-31299.html)



Form Validation Rules - What i am doing wrong? - El Forum - 06-14-2010

[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 />
        &lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50"&gt; <br />
        Passowrd:  <br />
        &lt;input type="paswword" name="password" value="&lt;?php echo set_value('password'); ?&gt;" size="50"&gt; <br />
        Confirme Password: <br />
        &lt;input type="paswword" name="passwordconfirm" value="&lt;?php echo set_value('passwordconfirm'); ?&gt;" size ="50"&gt;&lt;br />
        Endereço de e-email:<br />
        &lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="50"&gt;&lt;br />
        Confirmação de e-mail:<br />
        &lt;input type="text" name="emailconfirm" value="&lt;?php echo set_value('emailconfirm'); ?&gt;" size= "50"&gt;&lt;br />

        &lt;!-- Esta div separada serve para ter o butão "afastado" do restante--&gt;
        <div id="submit">
            &lt;input type="submit" name="submit" value="Submit"&gt; <br />
        </div>

    &lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
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


Form Validation Rules - What i am doing wrong? - El Forum - 06-14-2010

[eluser]WanWizard[/eluser]
And what is exactly your question?

What is the error? What would you expect would happen? What have you already tried?


Form Validation Rules - What i am doing wrong? - El Forum - 06-14-2010

[eluser]Alfredo Palhares[/eluser]
Sorry, My problem is that the only the rule required is working, for example the matches doesn't work, or the trim, or valid_email


Form Validation Rules - What i am doing wrong? - El Forum - 06-14-2010

[eluser]Simian Studios[/eluser]
Code:
array (
    'filed' => 'password',

Not tested, but correct this typo and see how it goes.. can't see anything else wrong TBH...