eZ Community » Forums » Developer » Custom validation
expandshrink

Custom validation

Custom validation

Friday 11 November 2011 12:38:10 pm - 8 replies

Hello community.

I use a simple extension to apply a custom validation, but I have a problem with post variable complex name. Now I explane better...

This is my extension

 <?
class MaskinsValidatorHandler extends eZContentObjectEditHandler
{
    function __construct() { }
    function fetchInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) { }
    static function storeActionList() { }
    function publish( $contentObjectID, $contentObjectVersion )
    {
        eZDebug::writeDebug("MaskinsValidatorHandler:publish");
    }
    function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
    {
        eZDebug::writeDebug("MaskinsValidatorHandler:validateInput");
        $result = array( 'is_valid' => true, 'warnings' => array() );
        $isValid =& $result['is_valid'];
        $warnings =& $result['warnings'];
        if($class->Identifier == 'user')
        {
            eZDebug::writeDebug("MaskinsValidatorHandler:validateInput:user");
            eZDebug::writeDebug(print_r($_POST,true));
            $this->getAttributeValue($contentObjectAttributes,"user_type");
        }
        return $result;
    }
    private function getAttributeValue($contentObjectAttributes, $attribute_name)
    {
        $bFound = false;
        $ret = '';
        $arrayCount = count($contentObjectAttributes);
        for($i = 0; $i < $arrayCount && !$bFound; $i++)
        {
            $attribute = $contentObjectAttributes[$i];
            if($attribute->ContentClassAttributeIdentifier == $attribute_name)
            {
                /*
                Here I need to read the $_POST array.
                But what is the complex post variable name?
                */
                eZDebug::writeDebug(print_r($attribute,true));
                $bFound = true;
            }
        }
        return $ret;
    }
}
?>

And this is the post variable name:

Array
(
    [ContentObjectAttribute_id] => Array
    (
        [0] => 1088
        [1] => 1089
        [2] => 1090
        [3] => 1091
        [4] => 1092
        [5] => 1093
        [6] => 1094
        [7] => 1095
        [8] => 1096
        [9] => 1097
        [10] => 1098
        [11] => 1099
        [12] => 1100
    )
    [ContentObjectAttribute_ezselect_selected_array_1088] => Array
        (
            [0] => 1
        )
    [ContentObjectAttribute_ezstring_data_text_1089] =>
    [ContentObjectAttribute_ezstring_data_text_1090] => 
    [ContentObjectAttribute_ezstring_data_text_1091] => 
    [ContentObjectAttribute_ezstring_data_text_1092] => 
    [ContentObjectAttribute_data_user_login_1093] => test
    [ContentObjectAttribute_data_user_password_1093] => test
    [ContentObjectAttribute_data_user_password_confirm_1093] => 
    [ContentObjectAttribute_data_user_email_1093] => 
    [ContentObjectAttribute_data_user_email_confirm_1093] => 
    [ContentObjectAttribute_ezstring_data_text_1094] => 
    [ContentObjectAttribute_ezstring_data_text_1095] => 
    [ContentObjectAttribute_ezstring_data_text_1096] => 
    [ContentObjectAttribute_ezstring_data_text_1097] => 
    [ContentObjectAttribute_ezstring_data_text_1098] => 
    [ContentObjectAttribute_country_1099] => Array
        (
            [0] => IT
        )
    [ContentObjectAttribute_ezstring_data_text_1100] => 
    [PublishButton] => Register
)

 

How can I read right post variable? How can I know the complex attribute name?

Thank You.

Modified on Friday 11 November 2011 12:52:20 pm by Domenico Garozzo

Friday 11 November 2011 2:34:42 pm

Maybe using a custom datatype or a workflow event would be better suited to your needs?

Friday 11 November 2011 2:52:04 pm

Maybe using a custom datatype or a workflow event would be better suited to your needs?

Hi Gaetano,
thank you for your answer.

My extension work very well, the problem is read the right value.

How standard validation read the post variable?

I need only this code, so that i can use my custom validator.

Thank you,
Domenico

Modified on Friday 11 November 2011 4:52:52 pm by Domenico Garozzo

Friday 11 November 2011 3:07:26 pm

Hello Domenico,

Yes I hear that you wish to only change your code only as much as you have to but ... you should listen to Gaetano with regard to his datatype suggestion, as datatype PHP does have code to read input variables such as these for exactly this purpose. Here is an example ...

https://github.com/ezsystems/ezpublish/blob/master/kernel/classes/datatypes/ezstring/ezstringtype.php#L88

 

I hope this helps ...

 

Cheers,

Heath

Friday 11 November 2011 4:52:21 pm

Thank you Heath,
I have resolved this problem.

Now I read the post variable value!

My custom validator is ok, now the problem is show the error.

The eZContentObjectEditHandler::validateInputHandlers return an array of error but the register form don't show it.

I suppose that user module reset this array, my question is where?

Than you,
Domenico

Modified on Friday 11 November 2011 4:53:23 pm by Domenico Garozzo

Friday 11 November 2011 6:20:36 pm

Ok, I have  found the problem.

The eZContentObject::validateInput is called for the standard validation but when my custom handler is called no.

This mean that my error are not include in error array by this code:

$unvalidatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ),
                                                    'identifier' => $contentClassAttribute->attribute( 'identifier' ),
                                                    'name' => $validationName,
                                                    'description' => $description );

There is a method to read this array and add my error?

Thank you.

Friday 11 November 2011 7:07:34 pm

Ok!!!! SOLVED!!!

The custom validation is in $validation.custom_rules variable!

Now I need only customize the template to read this attribute!

Thank you very much for answers!

(If someone want the extension to see the code, contact me!)

Modified on Saturday 12 November 2011 1:43:34 pm by Domenico Garozzo

Saturday 12 November 2011 3:25:11 am

Hello Domenico,

 

Apologies for my late follow up reply. I was called away today and unavailable. A very productive but busy day (probably for both of us happy.gif Emoticon

 

I have to say. I'm very pleased that you reached your goals. I am even (a little embarrassed to say) impressed that you so quickly deduced and solved the problem yourself. I don't see this enough (though it is everywhere).

 

Best wishes

 

Cheers,

 

Heath

Modified on Saturday 12 November 2011 3:26:24 am by // Heath

Saturday 12 November 2011 1:52:25 pm

Thank you Heath!

But problem was simpler than it seemed.

However, it was really exciting to find the solution!

I wish you a pleasant weekend.

Domenico

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from