form validation matches problem #1957

Closed
hakimihamdan88 opened this Issue Nov 2, 2012 · 12 comments

Comments

Projects
None yet
5 participants
@hakimihamdan88

form validation matches bug

@narfbg

This comment has been minimized.

Show comment Hide comment
@narfbg

narfbg Nov 2, 2012

Contributor

And the bug is ... ?
Come on man, it's not like this is your first bug report.

Contributor

narfbg commented Nov 2, 2012

And the bug is ... ?
Come on man, it's not like this is your first bug report.

@hakimihamdan88

This comment has been minimized.

Show comment Hide comment
@hakimihamdan88

hakimihamdan88 Nov 2, 2012

form validation still output "not match" when matched

form validation still output "not match" when matched

@narfbg

This comment has been minimized.

Show comment Hide comment
@narfbg

narfbg Nov 2, 2012

Contributor

Still? Since when? Can you show code?

Contributor

narfbg commented Nov 2, 2012

Still? Since when? Can you show code?

@hakimihamdan88

This comment has been minimized.

Show comment Hide comment
@hakimihamdan88

hakimihamdan88 Nov 2, 2012

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
if ($this->form_validation->run()) {
}
<?php echo validation_errors(); ?>

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

<h5>Password</h5>
<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />

<h5>Password Confirm</h5>
<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />

<div><input type="submit" value="Submit" /></div>
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
if ($this->form_validation->run()) {
}
<?php echo validation_errors(); ?>

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

<h5>Password</h5>
<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />

<h5>Password Confirm</h5>
<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />

<div><input type="submit" value="Submit" /></div>
@it-can

This comment has been minimized.

Show comment Hide comment
@it-can

it-can Nov 2, 2012

Contributor

The matches rule needs to be at the end...

$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run()) {
}

Contributor

it-can commented Nov 2, 2012

The matches rule needs to be at the end...

$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run()) {
}

@narfbg

This comment has been minimized.

Show comment Hide comment
@narfbg

narfbg Nov 2, 2012

Contributor

Has that ever worked in that particular order?

Contributor

narfbg commented Nov 2, 2012

Has that ever worked in that particular order?

@hakimihamdan88

This comment has been minimized.

Show comment Hide comment
@hakimihamdan88

hakimihamdan88 Nov 3, 2012

ah now it works.
now i need to change all the code. how come suddenly change
http://codeigniter.com/nightly_user_guide/libraries/form_validation.html still use

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');

ah now it works.
now i need to change all the code. how come suddenly change
http://codeigniter.com/nightly_user_guide/libraries/form_validation.html still use

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
@GDmac

This comment has been minimized.

Show comment Hide comment
@GDmac

GDmac Nov 3, 2012

Contributor

I downloaded the oldest version available of CI, and indeed, it has always been in the wrong order in the docs.
(edit: the docs were right, the matches method has changed)

This breaks backward compatibility with 2.x.!
Declaring matches[] first has always been perfectly valid.
The matches() method has changed from comparing $str to $_POST[$field],
and it now compares $str against set form data: $this->_field_data[$field]['postdata']

Contributor

GDmac commented Nov 3, 2012

I downloaded the oldest version available of CI, and indeed, it has always been in the wrong order in the docs.
(edit: the docs were right, the matches method has changed)

This breaks backward compatibility with 2.x.!
Declaring matches[] first has always been perfectly valid.
The matches() method has changed from comparing $str to $_POST[$field],
and it now compares $str against set form data: $this->_field_data[$field]['postdata']

@GDmac

This comment has been minimized.

Show comment Hide comment
@GDmac

GDmac Nov 3, 2012

Contributor

@narfbg the way the matches() method matches, doesn't match 2.x, it breaks backward compatibility.

Contributor

GDmac commented Nov 3, 2012

@narfbg the way the matches() method matches, doesn't match 2.x, it breaks backward compatibility.

@GDmac

This comment has been minimized.

Show comment Hide comment
@GDmac

GDmac Nov 3, 2012

Contributor

@narfbg , thanks, nice , a "matching" workaround.

Contributor

GDmac commented Nov 3, 2012

@narfbg , thanks, nice , a "matching" workaround.

nonchip pushed a commit to nonchip/CodeIgniter that referenced this issue Jun 29, 2013

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Mar 25, 2016

Hi,

if you use the crypto SHA1 attention to the confirmation line, place the code | sha1 before the function matches [xxx] if the code does not work ???

codeIgniter 3.0.6 http://bforbyoos.com application BforBYOOS

` //if this is a new account require a password, or if they have entered either a password or a password confirmation
if ($this->input->post('password') != '' || $this->input->post('confirm') != '' || !$id)
{

        $this->form_validation->set_rules('password', 'lang:password', 'required|min_length[6]|sha1');

        $this->form_validation->set_rules('confirm', 'lang:confirm_password', 'required|sha1|matches[password]');
    }`

P.S updated codeigniter 3.0.6 modification is correct. the 26 march 2016
Gabriel BYOOS

ghost commented Mar 25, 2016

Hi,

if you use the crypto SHA1 attention to the confirmation line, place the code | sha1 before the function matches [xxx] if the code does not work ???

codeIgniter 3.0.6 http://bforbyoos.com application BforBYOOS

` //if this is a new account require a password, or if they have entered either a password or a password confirmation
if ($this->input->post('password') != '' || $this->input->post('confirm') != '' || !$id)
{

        $this->form_validation->set_rules('password', 'lang:password', 'required|min_length[6]|sha1');

        $this->form_validation->set_rules('confirm', 'lang:confirm_password', 'required|sha1|matches[password]');
    }`

P.S updated codeigniter 3.0.6 modification is correct. the 26 march 2016
Gabriel BYOOS

@flexsingit

This comment has been minimized.

Show comment Hide comment
@flexsingit

flexsingit Jun 23, 2017

All the validation rules having parameters in them are giving internal server error ,

$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[12]');
$this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'required|min_length[6]|max_length[12]|matches[password]');

All the validation rules having parameters in them are giving internal server error ,

$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[12]');
$this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'required|min_length[6]|max_length[12]|matches[password]');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment