Part of the EllisLab Network
   
 
Missing code? Validation.php
Posted: 09 May 2007 05:36 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  21
Joined  12-07-2006

For anybody that uses $this->validation->(fieldname)_error in their code for showing individual errors, have you ever noticed that it doesn’t work for fields when you leave them blank?  this seems just be a small oversight.  To fix it I just added the following lines at Line 231 in the run() method.

// Set the error variable.  Example: $this->username_error
$error = $field . '_error';
$this->$error = $this->_error_prefix . sprintf($line, (!isset($this->_fields[$field])) ? $field : $this->_fields[$field]) . $this->_error_suffix;

It’s pretty much a duplication of the code at line ~ 331.  Just in case this helps somebody.
PS: Annoying fact #2: you can’t post on this forum with Javascript disabled. -_-

 Signature 

http://www.dovka.org/

Profile
 
 
Posted: 09 May 2007 09:14 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  30
Joined  03-26-2007

When you say “leave the fields blank” you mean on the HTML form right? What sort of elements are failing for you?

Profile
 
 
Posted: 09 May 2007 09:59 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  8
Joined  04-10-2007
ZareMedia - 09 May 2007 09:14 AM

When you say “leave the fields blank” you mean on the HTML form right? What sort of elements are failing for you?

I’m getting the same problem. error_string is filled out but {$myinput}_error isn’t.

I have a required rule on my radio buttons, and if these aren’t checked by the user I get the same problem.

In Validation::run() the isset/required rule is handled as a special case and so has different error-message handling compared to the other rules. I’ve just hacked together a patch to merge the two..

.. but seems it’s a bit to big to post here grin I’ll try putting it into the bugzilla section.

Which didn’t work either!
Patch is here if anyone wants a look.

Cheers,
Matt.[

Profile
 
 
Posted: 10 May 2007 01:03 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  21
Joined  12-07-2006

Yes, my problem was the same (usually radio and check inputs cause the issue it seems?).
I needed to get individual errors and as Matt says, {$name}_error wasn’t being propogated but the error_string variable was.

Definately a bug, IMO.

 Signature 

http://www.dovka.org/

Profile
 
 
Posted: 10 May 2007 03:42 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  5
Joined  05-05-2007

I noticed the same bug. If the submitter does not check the checkbox (which is marked as required in the validator) it will not return my desired custom error message.

That’s my code:

controller:

/* .... */
$rules['terms']          = "required";
$this->validation->set_rules($rules);
/* .... */
$fields['terms']         = $this->lang->line('register_terms');
$this->validation->set_fields($fields);
/* .... */

view:

<p id="termsParagraph">
<
input type="checkbox" name="terms" value="yes" id="terms" <?=$this->validation->set_checkbox('terms', 'yes'); ?> /> <label for="terms">Ich stimme den <a href="about/terms">Nutzungsbedingungen</a> zu</label>
<?=$this->validation->terms_error; ?>
</p>

terms_error just returns an empty string.

Anybody got a bugfix or a workaround? The above mentioned bugfix doesn’t work for me (version 1.5.1).

The validation itself seems to work, just no error_string passed.

Profile
 
 
Posted: 10 May 2007 03:45 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  21
Joined  12-07-2006

yep, the first post details the fix. smile

 Signature 

http://www.dovka.org/

Profile
 
 
Posted: 10 May 2007 04:24 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  5
Joined  05-05-2007

I’m really sorry, but I cannot follow you.

Line 231 from the beginning of the file?

In my Validation.php there’s is already something in this line:

$field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field];

Should I just overwrite it? Add your code before or after?

Is this the right block I am looking for:

/*
             * Are we dealing with an "isset" rule?
             *
             * Before going further, we'll see if one of the rules
             * is to check whether the item is set (typically this
             * applies only to checkboxes).  If so, we'll
             * test for it here since there's not reason to go
             * further
             */
            
if ( ! isset($_POST[$field]))
            
{            
                
if (in_array('isset', $ex, TRUE) OR in_array('required', $ex))
                
{
                    
if ( ! isset($this->_error_messages['isset']))
                    
{
                        
if (FALSE === ($line = $this->CI->lang->line('isset')))
                        
{
                            $line
= 'The field was not set';
                        
}                            
                    }
                    
else
                    
{
                        $line
= $this->_error_messages['isset'];
                    
}
                    
                    $field
= ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field];          // <------- this is line 231
                    
$this->_error_array[] = sprintf($line, $field);    
                
}
                        
                
continue;
            
}
Profile
 
 
Posted: 10 May 2007 04:26 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  21
Joined  12-07-2006

just before that line, insert it at 230! sorry for the confusion smile

 Signature 

http://www.dovka.org/

Profile
 
 
Posted: 10 May 2007 04:28 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  5
Joined  05-05-2007

You’re right!

Thank you very much for your help!

Profile
 
 
Posted: 10 May 2007 04:29 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  21
Joined  12-07-2006

No worries :D

 Signature 

http://www.dovka.org/

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 119125 Total Logged-in Users: 60
Total Topics: 125465 Total Anonymous Users: 4
Total Replies: 660486 Total Guests: 460
Total Posts: 785951    
Members ( View Memberlist )
Newest Members:  kracha95tanjahagresifBlunklenarezecomodlostunlockedmarcusbrody10ghadbanRachelRiley