Part of the EllisLab Network
This thread is a discussion for the wiki article: MY Form validation - Callbacks into Models
   
 
MY Form validation - Callbacks into Models
Posted: 03 May 2009 07:24 PM   [ Ignore ]  
Summer Student
Total Posts:  6
Joined  01-18-2009

I’ve been trying out this extension of the Form Validation Class and it was working as intended until I came to an error where I wanted to callback a validation function that was in the controller.

If my callback was “callback_user_model->isEmailUnque”, that would work fine. But if I was to instead have a callback like “callback_controllerCheckFunc”, it just would not recognise it

Does anyone know if this extension was meant to have callbacks done via the model ONLY?

Anyhows I had managed to find the problem which was the IF statement at line 238

if (list($class, $method) = split('->', $rule))
{
    
if ( ! method_exists($parent->$class, $method))
    
{         
        
continue;
    
}

        $result
= $parent->$class->$method($postdata, $param);
}
else
{
    
if ( ! method_exists($parent, $rule))
    
{         
        
continue;
    
}

    $result
= $parent->$rule($postdata, $param);  
}

Turns about the IF statement(Line 238) was returning TRUE regardless if the rule had “->” or not.

I’ve changed Line 238 to the following

list($class, $method) = split('->', $rule);
if (!empty (
$class) && !empty ($method))
{
    
if ( ! method_exists($parent->$class, $method))
    
{         
        
continue;
    
}

        $result
= $parent->$class->$method($postdata, $param);
}
else
{
    
if ( ! method_exists($parent, $rule))
    
{         
        
continue;
    
}

    $result
= $parent->$rule($postdata, $param);  
}

That should now check it explicitly now.

Can anyone confirm if I am on the right path here or have I just totally misunderstood the problem I was facing and fixed it unnessary?

Profile
 
 
Posted: 22 June 2009 01:39 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  24
Joined  09-20-2008

To get the language libary work with this extension you need to do this:

On line 341 from system\application\libraries\MY_Form_validation.php
Change:

$message = sprintf($line, $row['label'], $param);

For:

$message = sprintf($line, $this->_translate_fieldname($row['label']), $param);

Good work, very useful extension :D

Profile
 
 
Posted: 22 June 2009 01:57 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  24
Joined  09-20-2008

if you want to use a hole message error translation you need use this:
On line 341 from system\application\libraries\MY_Form_validation.php

$message = sprintf($this->_translate_fieldname($line), $this->_translate_fieldname($row['label']), $param);
Profile
 
 
Posted: 22 June 2009 02:15 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  24
Joined  09-20-2008

if you would like to Automatic take erro message from lang array add this on line 328

// Automatic take erro message from lang array
                
if($callback === TRUE){
                    $this
->set_message($rule, 'lang:erro'.substr($rule,2+strpos($rule,'->')) );
                
}
Profile
 
 
Posted: 27 June 2009 09:49 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  24
Joined  09-20-2008

For me only work when I edited the line 54 untill 61
before:

$uri = ($group == '') ? trim($parent->uri->ruri_string(), '/') : $group;
            
            if (
$uri != '' AND isset($this->_config_rules[$uri]))
            
{
                $this
->set_rules($this->_config_rules[$uri]);

after:

$uri = ($group == '') ? $this->_config_rules[trim($parent->uri->ruri_string(), '/')] : $group;
            
            if (
$uri != '' AND isset($this->_config_rules[trim($parent->uri->ruri_string(), '/')]))
            
{
                $this
->set_rules($this->_config_rules[trim($parent->uri->ruri_string(), '/')]);

anyone read me?

Profile
 
 
   
 
 
‹‹ In model file      Wick ››
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 819, on March 11, 2010 11:15 AM
Total Registered Members: 120609 Total Logged-in Users: 42
Total Topics: 126644 Total Anonymous Users: 2
Total Replies: 665736 Total Guests: 495
Total Posts: 792380    
Members ( View Memberlist )