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!
18.
Using More Fields: email and repeated
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
Hi Ryan,
I am seeing "Updated 4 days ago" next to the tutorial heading, just out of curiosity how can i know what was updated?
Regards,
Baig
We're working on that - the "Updated" feature is not useful yet! In this case, it was a very minor tweak of some non-important screencast metadata. That's something we're planning on making *much* more useful soon - I also want to see exactly *what* has been updated!
Hi Ryan,
I am hoping that you can push me in right direction.
I am working on a product where on an form fields are hard coded in a formtype class just like any form on a website but now i need to allow user to create more fields using an admin panel. The admin panel is all taken care of but i am stuck at how to allow them to create more fields and make sure they appear on front end with the form.
Cant seem to find any bundle either that does this.
Baig
Hey :)
Hmm, so this is not a problem I've had to solve personally - but it is a problem that others have, so it's good that you searched first for a bundle / existing solution. But, here's one potential direction:
1) Somehow, your users create "new" fields in the admin panel. I'm assuming that this "field creation" is a different screen than where people actually fill out the forms (it's like a schema-creation tool, in a sense). Somehow, you save these to the database - with information about the field types, etc
2) Create a new form class - e.g. DynamicFieldsType. Allow this type (in configureOptions) to have an option passed in - something like "fields", which would be an array of information about the fields that should be added. You'll be able to reference this "fields" option in buildForm(). You'll send this information in via the controller:
3) In buildForm, use this "fields" option to completely, dynamically build your form. If you need validation, you'll need to add it via the "constraints" option for each field (since there is no entity behind this).
4) Finally, you can use this form directly if you want (like I've shown above). OR, if these fields are part of a bigger form, you'll need to embed this form in your main form (e.g. MainAdminType). In that case, you'll also need to pass a fields option to the main type so that you can pass this option into the child type (DynamicFieldsType). Or, you could also inject the EntityManager into DyanmicFieldsType and register it as a service.
I hope that somewhat gives you some ideas - at least from someone who has not actually had to solve this before :). There are probably even "cooler" solutions involving form events... but I don't see the point: just query the DB for the fields you need and dynamically build the form.
Cheers!
Thanks Ryan
"Houston: no signs of life"
Start the conversation!