Skip to content

Laravel validation #13

@barryvdh

Description

@barryvdh

To make it easy to validate, we can use the Laravel validator with Symfony forms:

 $form = $factory->create(FormType::class, $user)
        ->add('name', TextType::class, [
            'rules' => 'required',
        ])
        ->add('email', EmailType::class, [
            'rules' => 'email|unique'
        ]);

This would run the validator post-submit, so you can check $form->isValid() after submitting the form. When failed, the errors on the form are added.

This seems to work already with this commit: 811ca4c

Next step would be to:

  • Make the required option based on the rule, but this would change the default (Symfony default is required = true), to make front-end always in sync with back-end validation
  • Add HTML5 attributes for rules (eg; min:3 -> minlength attribute etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions