Skip to content

Validate Carve input ​

Add the validator rule to reject content that exceeds a length limit or uses markup your application does not allow.

Validate a visitor comment ​

In a table's validationDefault() method:

php
$validator->setProvider('carve', \MarkupCarve\CakeCarve\Validation\CarveValidation::class)
    ->add('body', 'carve', [
        'rule' => ['valid', ['preset' => 'comment', 'profile' => 'comment', 'maxLength' => 500]],
        'provider' => 'carve',
    ]);

For a five-character limit, CarveValidation::valid('Hello world', ['preset' => 'comment', 'maxLength' => 5]) returns Carve content is too long. Length is measured in rendered plain text. Empty values pass this rule; add CakePHP presence and nonempty rules when content is required.

Choose rule options ​

OptionDefaultWhat it does
presetdefaultUses a configured render preset.
profileFrom preset or configLimits markup; comment suits visitor text.
onDisallowedstripSelects strip, to_text, or error for disallowed markup.
strictfalseRejects parse warnings.
lintfalseRejects lint findings.
lintRulesAll rulesLimits lint checks to listed rule IDs.
ignoreLintRules[]Excludes listed lint rule IDs.
minLengthNoneRequires a minimum plain text length.
maxLengthNoneSets a maximum plain text length.

Profile violations return Carve content contains markup disallowed by its profile. Lint and parse messages show up to three findings with line, column, rule, and message. The engine's lint findings have no severity field. See safe mode for render settings to pair with validation.

Released under the MIT License.