Part of the EllisLab Network

Bug Report

required rule throws unknown index when field empty

Date: 10/15/2008 Severity: Major
Status: Resolved Reporter: drewbee
Version: 1.7.0 SVN
Keywords: Libraries, Validation Class
Forum Thread: http://codeigniter.com/forums/viewthread/89251/P135/

Description

When setting field rules and using the ‘required’ attribute, if a field is left blank, an unknown index $rule is thrown instead of properly displaying the error message.

Removing the ‘required’ rule in the rule list results in no unkonwn index error being thrown.

Note: This is from the latest build; This just showed up from one of the last few builds, as it was not an issue before.

This is also from the new *Form Validation* class - I did not see an option for it on the ‘bug type’

Code Sample

// Doesn't work
        
$fields = array(
                    array(
'field'     => 'email',
                          
'label'     => '',
                          
'rules'     => 'trim|required|max_length[30]|valid_email|callback__validUser'                        );

                        
// Works
        
$fields = array(
                    array(
'field'     => 'email',
                          
'label'     => '',
                          
'rules'     => 'trim|max_length[30]|valid_email|callback__validUser'                        );
        
$this->form_validation->set_rules($fields);

Expected Result

Error message displays next to corresponding field.

Actual Result

A PHP Error was encountered
Severity: Notice

Message: Undefined variable: rule

Filename: libraries/Form_validation.php

Line Number: 517

A PHP Error was encountered
Severity: Notice

Message: Undefined index:

Filename: libraries/Form_validation.php

Line Number: 517

Comment on Bug Report

Page 1 of 1 pages
Posted by: barbazul on 15 October 2008 11:37pm
barbazul's avatar

This has already been reported in:

http://codeigniter.com/bug_tracker/bug/5311/


I posted a fix there but ir hasn’t been commited yet

Posted by: drewbee on 16 October 2008 10:02am
drewbee's avatar

AH ok, didn’t see it. Thanks!

Please mark as duplicate.

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?