A
A
Andrey Shakhtarin2016-10-27 12:43:55
symfony
Andrey Shakhtarin, 2016-10-27 12:43:55

Form validation with custom flash messages Symfony2?

How to properly validate a form?
What we have:
There is an essence

class Product
{
     private $product;

/**
     * Set product
     *
     * @param string $product
     *
     * @return Product
     */
    public function setProduct($product)
    {
        $this->product = $product;

        return $this;
    }

    /**
     * Get product
     *
     * @return string
     */
    public function getProduct()
    {
        return $this->product;
    }
}

There is a form type:
class ProductType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    //...
        $builder
            ->add('product')
       //...
            ->add('save', SubmitType::class);
        ));
    }
//...
}

and there is field validation:
//App/NameBundle/Resource/config/validation.yml
App\EducationBundle\Entity\Product:
    properties:
        product:
            - Length: { min: 5, minMessage: 'Каши не ел? Добавь еще символов!'}

Missed something, perhaps. When sent, it displays the default flash message, "See the required ...".
Is it possible to implement my custom message? If so, how can it be implemented. Help me solve this problem please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Shakhtarin, 2016-10-27
@AndreyShakhtarin

There is no solution for this thread

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question