1

Well,I actually tested my form code in Chrome, Firefox and IE, but then when a friend tested my form in his Mac I discovered that the required field doesn't worked, because Safari doesn't accept the required class. So, at the end of the form when I press the send button I got the database error and it crashes.

I searched into the Symfony documentation and I found this piece of code on the form class:

public function setDefaultOptions(OptionsResolverInterface $resolver) {
    $collectionConstraint = new Collection(array(
    'name' => array(
        new NotBlank(array('message' => 'Name should not be blank.')),
    )
    ));

    $resolver->setDefaults(array(
        'constraints' => $collectionConstraint
    ));
}

But it seems to do nothing. Also I put on the Entity class this:

/**
 * @Assert\NotBlank()
 */
public $name;

And still get the error. Any ideas what am I doing wrong? Thanks!

Tom Tom
  • 3,680
  • 5
  • 35
  • 40
Jose M
  • 205
  • 1
  • 2
  • 11

1 Answers1

2

The problem with Safari is that it recognizes the HTML5 required attribute but it doesn't stop the form from being submited. You need to use javascript to check it.

This post should help with that.

Community
  • 1
  • 1
Tom Tom
  • 3,680
  • 5
  • 35
  • 40
  • 1
    this is spot on, but also you need to be still validating server side anyways. **never** rely on client side validation alone. – DevDonkey Dec 06 '15 at 18:27
  • 2
    He'll have to check the form server-side yes, but he should already be doing that really because HTML5 validation can be worked around. – Tom Tom Dec 06 '15 at 19:00