Chapters
36 Chapters
|
1:50:44
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.3.3
Subscribe to download the code!Compatible PHP versions: >=5.3.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
24.
Server-Side Validation
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4", // v2.4.2
"doctrine/orm": "~2.2,>=2.2.3", // v2.4.2
"doctrine/doctrine-bundle": "~1.2", // v1.2.0
"twig/extensions": "~1.0", // v1.0.1
"symfony/assetic-bundle": "~2.3", // v2.3.0
"symfony/swiftmailer-bundle": "~2.3", // v2.3.5
"symfony/monolog-bundle": "~2.4", // v2.5.0
"sensio/distribution-bundle": "~2.3", // v2.3.4
"sensio/framework-extra-bundle": "~3.0", // v3.0.0
"sensio/generator-bundle": "~2.3", // v2.3.4
"incenteev/composer-parameter-handler": "~2.0", // v2.1.0
"doctrine/doctrine-fixtures-bundle": "~2.2.0", // v2.2.0
"ircmaxell/password-compat": "~1.0.3", // 1.0.3
"phpunit/phpunit": "~4.1" // 4.1.0
}
}
5 Comments
Following along wit the tutorial during the server side validation portion I have the @Assert/Regex as shown. But error message for that field always comes up "The value is not valid". I do have the use statement all other errors using @Assert work. What could I be missing
Hi Neal!
I don't know the answer, but I can help point you in the right direction. The "The value is not valid" is a message that doesn't come from the @Assert\-style validation - it's actually coming from the form field itself. For example, if setup a field to be a "number" form field type, and then type in a string, you'll get this error (some browsers prevent this, but just follow my idea). I call this type of validation, "sanity validation" - it's when the value you put in just doesn't make sense at all for the field type you did. So double-check what field type you have and see what's going on - but don't worry about your @Assert stuff - the issue isn't there :).
Here's an example of where that message comes from for the integer type (but this message is used if you fail "sanity validation" on any form field type): http://symfony.com/doc/curr...
Let me know how it goes!
Thanks Ryan,
The field type is set to password
$builder
->add('username', 'text')
->add('email', 'email', array(
'required' => false,
'label' =>'Email Address',
'attr' => array('class' => 'C-3P0')
))
->add('plainPassword', 'repeated', array(
'type' => 'password'
));
Which I would think would just be a string. The private $plainPassword is set to @var string and the getter and setter for it are both using string. At a loss here I'm sure is is something simple that I am just over looking.
Hey Neal!
You're right - the password type does *not* have any of this "sanity validation" on it, nor does the email type of the text type. With the form you posted, the only place it could be coming from is the "repeated" type, which will throw this error if the passwords don't match. To absolutely make sure that the problem is being caused by the plainPassword field, add the invalid_message option to it (http://symfony.com/doc/curr... and set it to something different than "this value is not valid". If this successfully changes the message, then the issue is *definitely* that Symfony thinks that the 2 password fields don't match. Then, it should be easier to debug :).
Cheers!
Thanks it was the repeated field getting to understand how all these interact is tricky. Great Tutorials. Look forward to whats to come
"Houston: no signs of life"
Start the conversation!