Search code examples
octobercmsoctobercms-backendoctober-form-controller

Octobercms backend Builder forms - Automatic validations?


I'm trying since a week to validate a backend Builder form...

Not using Builder validations rules with YAML, I put in my code $rules and $customMessages but they are note triggered when submitting my database.

My empty form is successfully created or updated !!! I thought Octobercms was doing the annoying validation job.

What I'm missing ? Thanks for helping, I'm driving crazy !

My Yaml has no validation rules :

 fields:
    client_name:
        label: 'Name'
        span: auto
        type: text

and my model is :

use Model;
use Validator;

/**
 * Model
 */
class Commande extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\SoftDelete;
    use \October\Rain\Database\Traits\Nullable;

    protected $nullable = ['comment'];    // Pour utilisation de Nullable trait

    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;


    /**
     * @var string The database table used by the model.
     */
    public $table = 'lb_book_commandes';

    /**
     * @var array Validation rules
     */
    public $rules = [
        'client_name' => 'required'
    ];

    // Messages d'erreur de validation
    public $customMessages = [
        'client_name.required' => 'Name not typed',
    ];

    // Affichage de plusieurs messages de validation en une fois.
    public $throwOnValidation = false;

}

Solution

  • Finally, I solved my problem with this post : OctoberCMS plugin show all the validations at once

    some code was disturbing validation...