Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Custom Form Validation

Started by Muut Archive 10 years ago · 2 replies · 583 views
10 years ago

Hello

Im trying to do some custom validation on a form, have made a plugin as per the Reference:Form Actions chapter in the documentation.

PHP
public static function getSubscribedEvents()
{
    return [
        'onFormProcessed' => ['onFormProcessed', 0]
    ];
}
public function onFormProcessed(Event $event)
{
    $form = $event['form'];
    $action = $event['action'];
    $params = $event['params'];

    switch ($action) {
        case 'uniqueUser':
        .
        . 
        .
}

This is called from form.md as:

process:

  • validate: uniqueUser

This crashes with the following error:

"Argument 1 passed to Grav\Plugin\FormPlugin::onFormValidationError() must be an instance of Grav\Toolbox\Event\Event, instance of RocketTheme\Toolbox\Event\Event given"

What am I missing?

10 years ago

Please paste your code in triple backticks. I can't make sense of this without your pasted content in code blocks.

10 years ago

Sorry, another try:

PHP
public static function getSubscribedEvents()

{

return [

‘onFormProcessed’ => ['onFormProcessed', 0]

];

}

public function onFormProcessed(Event $event)

{

$form = $event['form']; 

$action = $event['action'];

$params = $event['params'];

switch ($action) {

case ‘uniqueUser’:

.

.

.

}

This is called from form.md as:

TXT
process:

– validate: uniqueUser

This crashes with the following error:

TXT
“Argument 1 passed to Grav\Plugin\FormPlugin::onFormValidationError() must be an instance of Grav\Toolbox\Event\Event, instance of RocketTheme\Toolbox\Event\Event given

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago