Chapters
41 Chapters
|
4:45:40
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
18.
Agree to Terms Checkbox Field
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": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.1
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.6
"symfony/cache": "^3.3|^4.0", // v4.1.6
"symfony/console": "^4.0", // v4.1.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "^4.0", // v4.1.6
"symfony/framework-bundle": "^4.0", // v4.1.6
"symfony/property-access": "^3.3|^4.0", // v4.1.6
"symfony/property-info": "^3.3|^4.0", // v4.1.6
"symfony/security-bundle": "^4.0", // v4.1.6
"symfony/serializer": "^3.3|^4.0", // v4.1.6
"symfony/twig-bundle": "^4.0", // v4.1.6
"symfony/validator": "^4.0", // v4.1.6
"symfony/web-server-bundle": "^4.0", // v4.1.6
"symfony/yaml": "^4.0", // v4.1.6
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.6
"symfony/dotenv": "^4.0", // v4.1.6
"symfony/maker-bundle": "^1.0", // v1.8.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.6
"symfony/stopwatch": "^3.3|^4.0", // v4.1.6
"symfony/var-dumper": "^3.3|^4.0", // v4.1.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.6
}
}
9 Comments
Hi,
I am having trouble accessing the values of checkboxes. I am using a group of checkboxes - surrounded by a fieldset. In this fieldset every checkbox has the same name but each has an individual id and value. Trying to fetch the values via $request->query->get('nameofcheckbox'); I only get one of the values. But I need them all. All the values are stated in the URL but only the last one makes its way to my controller.
What am I doing wrong?
Thx
Oliver
Hey Oliver,
Hm, this sounds like you're using radio buttons instead of checkboxes. Usually, radio buttons allow you to select only one item from the list at the same time. But checkboxes allows you to select more than one item from the list at the same time. Are you sure you're using checkboxes and not radio buttons? Btw, could you show the code responsible for that form field in your form type? Probably you need to add a few specific options for them to work properly.
Cheers!
Hi Victor,
I am using CHECKboxes!
My code in the show.html.twig
This $auswahlKategorien is the variable that shows the value of just ONE checkbox instead of all selected.
Thx
Oliver
aaaaargh, I got it: I should choose different names for each checkbox!!! Thx
Hey Oliver!
Sorry for the slow reply! Ah, I missed the fact you create those checkboxes manually. Symfony usually takes care about unique names, but if you add extra fields manually in the template - you should care about unique names.
So yes, you're correct, the field name should be unique for all checkboxes otherwise the last will always overwrite the previous ones. But the radio buttons should work the reverse, they should have the same name because you can only choose the one option from the list.
Well done! I'm happy you were able to solve this problem yourself!
Cheers!
mapped => false might help me a lot when I dont know how to solve. Hopefully I will remember about this option :)
Hey Lijana Z.
It might be easier for you to remember it if you only remember that your form doesn't have to map all of its fields to a class
Cheers!
Hello Knp !
Is it possible to call services from entity ? Like repository or encode password ?
Cheers !
Hey Akavir S.
And the answer is no! But why do you need such functionality?
Cheers!
"Houston: no signs of life"
Start the conversation!