Welcome Guest, Not a member yet? Register   Sign In
Form Validation Error Messages for rule 'matches'
#1

[eluser]mradlmaier[/eluser]
Hi,

I am posting this here because I am not sure if this is a bug or if I am missing something.

I tried and modified the example in the userguide:


Quote:myform.php
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Benutzername</h5>
&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50" /&gt;

<h5>Passwort</h5>
&lt;input type="password" name="Passwort" value="&lt;?php echo set_value('Passwort'); ?&gt;" size="50" /&gt;

<h5>Wiederholung</h5>
&lt;input type="password" name="passconf" value="&lt;?php echo set_value('passconf'); ?&gt;" size="50" /&gt;

<h5>Email Addresse</h5>
&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="50" /&gt;

<div>&lt;input type="submit" value="Registrierung" /&gt;&lt;/div>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

As you can see I change the name of the first password field to 'Passwort' (That`s german.)

form.php
Code:
&lt;?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('username', 'Benutzername', 'required|min_length[4]|max_length[12]');
        $this->form_validation->set_rules('Passwort', 'Passwort', 'required|min_length[4]|max_length[12]');
        $this->form_validation->set_rules('passconf', 'Passwort Best&auml;gung', 'required|matches[password]');
        $this->form_validation->set_rules('email', 'Email Addresse', 'required|valid_email');
        
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?&gt;

I guess the expected behaviour for failing the 'matches' rule would be to display:

The Passwort Bestägung field does not match the Passwort field.

But it displays:

The Passwort Bestägung field does not match the password field.

Is this a bug or do I miss something here?
On another note, the ideal behaviour should be to display the "human" name of the field to match, wouldn`t it?

Michael
#2

[eluser]Pascal Kriete[/eluser]
You have a typo in there (2 actually - Bestätigung).

The rule should read:
Code:
$this->form_validation->set_rules('password', 'Passwort', 'required|min_length[4]|max_length[12]');
#3

[eluser]mradlmaier[/eluser]
Hi inparo,

You are right, there were some typos. So I changed it to

Code:
$this->form_validation->set_rules('username', 'Benutzername', 'required|min_length[4]|max_length[12]');
$this->form_validation->set_rules('Passwort', 'Passwort', 'required|min_length[4]|max_length[12]');
$this->form_validation->set_rules('passconf', 'Passwort Best&auml;gung', 'required|matches[Passwort]');
$this->form_validation->set_rules('email', 'Email Addresse', 'required|valid_email');

and it isplays like expected:

The Passwort Bestägung field does not match the Passwort field.

Neverless, I would like that the "human" name would be displayed instead the field name for the field to match... any ideas?

Michael
#4

[eluser]Pascal Kriete[/eluser]
Re-editing this post. I have it figured out now.

It works fine, but in your original example your matches rule referenced 'password', which didn't have a human name.




Theme © iAndrew 2016 - Forum software by © MyBB