burzum / cakephp-html-purifier

This is a CakePHP wrapper for the HTML Purifier lib. The plugin includes a trait, a view helper, a behavior and a shell to clean your markup wherever you like, in the view or in the model layer or clean any table and field using the shell.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation rules running HtmlPurifier

repher opened this issue · comments

Hey!

Do you have a good idea for this problem: i need to filter out all html tags only for validation. If validation runs without problems the tags should be saved.

Maybe your Behaviour may be a good spot for adding some validation rules. But using your Behaviour would cause beforeSave to run. Should we add another Behaviour just for validation functions?

I need this, because I have to count the number of words for some abstract submission form. It would be nice if we could add this kind of filtering to your Plugin somehow.

Bernhard

What do you mean by filter them out but validating only? This doesn't make any sense? You want to validate the markup if there are any invalid characters?

I do not know if HtmlPurifier can do that. The must be a method to just validate the rule set - or not.

The thing is, that on the one hand I need to filter out everything but

, and Tags. This is done with the HtmlPurifierComponent since the result is only stored in a session. On the other hand, I need to verify the data at the end of all input pages just before saving it to the database. In this verification process I need to count the number of words written in the rich text input field (which I purified earlier). To count them I was thinking to use HTMLPurifier to remove all tags and count the words with str_word_count().

Mmmh. But thinking again. Maybe a simple call to strip_tags() would give me the result I need ...

Mh. I guess I found a more practical way to validate the number of words:

        $value = strip_tags(
            trim( $value )
        );

        $wordcount = count(
            preg_split( '~[^\p{L}\p{N}\p{P}]+~u', $value )
        );

I may not be very fast, but it works :-)