Symfony2 - Dynamically modify form using user inputs - symfony

A little bit of background first. I learned in the past how to use "pure" php, and have more recently started using Symfony. I have been following several guides (Cookbook, Lynda & Openclassrooms) for many of my inquiries, but I haven't been able to find an answer for my current question.
I have two entities, let's name them User and Player. The User entity contains a Player property which can be null.
So, during a User creation, I would like 3 possibilities : leave the Player field empty, select an already-existing player, or create a new Player. At first I wanted to add a "Create new" option in the Player dropdown list, but have simply gone for a "Create new Player" checkbox.
The idea is, if the checkbox is checked, I would like to remove the Player dropdown list and add an embedded form to create a new Player. I have tried several events (PRE_SET_DATA, PRE_SUBMIT & co), but none seem to trigger according to a user input.
This is something that I would have done in JScript, but seeing how Symfony's a much different animal than pure php, I don't know how to do it. Any help or advice would be greatly appreciated !

You're on the right track there with PRE_SET_DATA and PRE_SUBMIT events.
You need to use JavaScript to reload form from server and Symfony form events to rebuild the form.
This is the documentation you're looking for: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html
Unfortunately, Symfony's form component is pretty complicated, so there are no simple code examples you can just take and use it without going through this article.
Also reading Form Events documentation is helpful for deeper understanding.

Related

cq:include default components in CQ form with server validation

I would like to customize start/end of OOTB CQ5 user form component to start with certain custom components pre-populated when the 'form' component is drag/dropped on to the page.
I currently have an over-laid /apps/foundation/components/form elements with start/end/actions customized. But I am to figure out way to add a component belonging to the FORM group, to the form start.......end to the page whenever a form is added to the page.
I have tried using a <cq:include path= "customComp" resourceType="/pathto/customComponent" /> to the jsp of the form-end component, this adds / shows the custom-component on display but does not perform the server-validations as it is not a separate node between the start and end nodes on the page, but a dynamically added one.
This is basically to enforce/mandate the use of my custom captcha component whenever a form is placed on a page.
thanks in Advance !
If you want to leave the form creation entirely to the author (as intended with OOTB components) there is no easy way to "sneak in" a mandatory captcha component. Even if you managed to put in the captcha component, the author can just delete it or move it out of your paragraph system.
Mingling the captcha with form-end might be possible, but not without reinventing the form-end component pretty much from scratch. I wouldn't want to do that.
I see three options that might be helpful to you:
Implement a jcr EventListener that will fire whenever a form is created or changed. Check the form data structure in jcr and when the mandatory captcha component is missing, add it and commit. This type of behaviour is of course a little shady and may suprise authors - but it's gonna work.
Build a wrapper form component that contains a paragraph system with a fully pre-configured form, including form-start, captcha and form-end. This approach my even save authors a bit of work and nobody will "forget" about the chaptcha easily. Nothing will stop an evil author from explicitly deleting the catpcha component however.
Build an entirely custom form component that does not utilizy any of the OOTB components. In this scenario you have full control over what the author can and cannot do. Most likely you will give up on a lot of flexibility in order to save development time and end up with a mostly static form where the author can edit a few cruicial parts.

Is there a way to hide optional fields while using autoforms in meteor

I'm using autoforms to build a rather lengthy form. SOme fields are populated by default values and I do not wish for them to appear since the end user will mostly not be touching them unless there is a specific necessity. I went through the documentation for autoforms and the demo page, but nothing is clearely mentioned about how to have these fields hidden away and then shown upon clicking on 'Advanced' or something like that. A little advice on how to get this thing going will be useful.
Documentation sources:
http://autoform.meteorapp.com/
https://www.google.co.in/search?q=afquickfieldschema&oq=afquickfieldschema&aqs=chrome..69i57.3232j0j1&sourceid=chrome&ie=UTF-8#q=afquickfield+options
Used simple collapsible s to meet this specific requirement.

Implement adding content only by some pople. Rails

I am working on dictionary-like web page and I want to implement adding/changing phrases only by few people (my client - which is some small organisation wants to be able to do this by himself). The page does not have any login/registration mechanism etc. (for regular users at least) so I do not want It to have any login button. I wondered if making admin model ( few admins made in seeds for example) and adding login button that is invisible - I thought of using CSS opacity for this one. Is this a good solution ? Is there any other good practice in these sitations? Please dont be afraid to post suggestions. Additionally this is a serious page (my first job as freelancer), so I wonder if my solution is... acceptable? Thanks in advance for any answers!
This quite a standard thing in the web. Most of the websites consists of two parts, customer facing part (sometimes called frontend) and admin panel (called backend). In your case you don't need any login to access frontend part, but you need one for backend part.
Creating hidden button is not needed at all. There simply should be no button at all. If you want to log in as an admin, you simply navigate to http://my-website-url.com/admin.
I wouldn't bother with roles et unless your client specified clearly that he needs them.
Even though this is simple I would still suggest adding a role to a user model. After all he may want to have some user functionality later on. The simplest way to do this would be to use devise and add a role enum column.
Check out the article below and look under the "Enum" section.
http://railsapps.github.io/rails-authorization.html

How to display additional form during views bulk operation?

I want to use the Views Bulk Operations (VBO) module to get the possibility to select nodes from a view and then do an action on each of them. However, this action requires additional data to be supplied by user, so what I need is to put another form in between VBO submit and the actual action processing.
I am using the *hook_action_info* hook to define my action. However, as I went through the *hook_action_info* documentation it seems to me that this is not doable using this hook as there is no configuration option to suppress the action bulk ajax update.
Can somebody confirm and/or propose better solution?
In short: User selects nodes from a view using checkboxes, after submitting the form another form appears asking for some more details (having list of nodes as hidden elements in it) and after submitting this one, e-mail is sent per every node. The body of the e-mails is always a combination of node data and the second form data.
Thanks a lot.
Petiar.
So, I decided to forget Views and VBO (no hard feelings) and create my own, custom form. The major thing which actually convinced me that this is not going to be a big issue is the tableselect form element type. I think this has been invoked in Drupal 7 and it is magical. At least worth have a look:
http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#tableselect
Thanks everybody for stopping by willing to help.

How to create facebook kind of comment for my blog

I am using C# asp.net. I want to implement a commenting system which is similar to facebook commenting system look & feel. Please give your inputs.
When it comes to storing,retrieving and displaying comments yes asp.net controls come into use.
Other things being done, to accept a comment and display existing ones for that object (may be post) I would do:
1: Retrieve the comments for that object from database. (easiest way is to use SqlDataSource and set Select, Insert and Delete commands)
2: Use ListView control to display the retrieved data . Remember ListView should be customized to fit you need
Other databound controls are also usable. With these rich controls this task should be easy. Play with the templates these controls offer you and you can achieve almost any database related task.
Design and styling are sufficiently supported and still CSS + can be easily integrated.

Resources