Hyperlinks in FOSUserBundle form label - forms

So I've searched, googled, asked and even consulted the stars, but I haven't been able to find a solution to this specific problem.
When overriding an FOSUserBundle form,(specifically the Change Password form, but generally any other FOSUserBundle form), is there a way to set part of the field label to be a hyperlink?
Does the question make sense? I could elaborate if it doesn't.
The goal
I would like to have resultant HTML to look like this:
<div>
<label for="fos_user_resetting_form_has_acceptedtos">I agree to the <a href='/tos/'>Terms Of Service</a>.</label>
<input id="fos_user_resetting_form_has_acceptedtos" type="checkbox" value="1" name="fos_user_resetting_form[has_acceptedtos]">
</div>
What I've tried. . .
I have added the has_acceptedtos field to the User.php Entity and hooked into the controller, as per the instructions. And I have customized the field labels successfully.
Unfortunately, the following syntax, unsurprisingly, doesn't work either:
# app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml
# ...
# Password change
change_password:
submit: Change password
has_acceptedtos: I agree to the <a href='/tos'>Terms Of Service</a>.
...
I have even attempted to override the template, in an attempt to artificially create a label that would appear in the vicinity of the checkbox via css. Didn't work out too well.
Other than re-writing the entire FOSUserBundle to generate my own forms, can this even be accomplished?
Thanks in advance for any suggestions!

You'll have to use a combination of custom form theming and the Twig "raw" method to accomplish this.
Here's an answer that deals with a quite similar issue.

Related

How to create a simple html form in symfony2 without using formbuilder

I have a (hopefully) simple problem:
I want to use a simple html form in a sympony2 project. The Problem is, that noting is sent by get through the form.
The Url after sending the form is: localhost:8888/de/search_art?
you see... there is no string after the ? !!!
The form looks like this:
<form class="navbar-form" role="search" method="get" action="{{ path('func_search_art') }}">
<input type="text">
<button type="submit" class="btn btn-default">Send</button>
</form>
This is my routing:
func_search_art:
path: /search_art/
defaults: { _controller: FuncSearchBundle:Search:SearchArt }
I don't want to do something within a controller for it, because it is in the navbar and for this it has to appear in every page. I don't want to initialize a form variable in every controller of the page for a simple navbar search field.
Is there a possiblity to create a simple form like this in symfony2 without using a form builder and so on ... ?
Greetz Michael
Yes, you can safely keep your form written in twig in the form you presented it. No need to create a form builder in every controller and send the form to twig. The only place you will have to build it is the SearchArtAction method from SearchController, where you have the handling functionality for this form.
Also you need to give a name to your text input.
<form class="navbar-form" role="search" method="get" action="{{ path('func_search_art') }}">
<input type="text" name="q">
<button type="submit" class="btn btn-default">Send</button>
</form>
Because your input lacks the name attribute , which is the relevant attribute to create the post data/query string.
You can't it will give you: "The CSRF token is invalid. Please try to resubmit the form". Regardless of that it actually work without it. For some reason Symfony serialized the forms. I particularly hate the fact that I need the form object to use forms, in many cases I found it overkill. Your $form->isValid will also failed, but the $form->isSubmitted() will not. One of the reasons I hate the form object is how tedious it is to populate a drop down with an EntityType, instead of making simple symfony manage to make the process a damn nightmare.

Polymer + form POST data

I have this
<form id="form_837299" class="appnitro" method="post" action="insert.php"> <paper-input label="Title" name="title" maxlength="255">
</paper-input>
<paper-input floatinglabel multiline label="text" name="text"></paper-input>
<li class="buttons">
<input type="hidden" name="form_id" value="837299" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
I have problem with POST data - nothing is sended in "text" and "title" (all in paper-input).
I modified the template and attribute "name" now is in one div, which Polymer created. But no data are sent.
print_r($_POST); shows me only this:
Array ( [form_id] => 837299 [submit] => Submit )
Anybody knows how use Polymer and Material UI on form?
Only elements that extend native form elements automatically get submitted with forms. paper-input extends core-input which has an input inside it as opposed to extending it. See this mailing list discussion for additional discussion and this StackOverflow post for possible solutions.
Something like this jsbin maybe?
Update: Here's the same thing in web component form.
Update: Looks like the creator of ajax-form has added this functionality.
Update: Also consider using iron-form.
According to the Polymer docs the way to do this is to just create a regular form input and wrap it in the <paper-input-decorator>
https://www.polymer-project.org/docs/elements/paper-elements.html#paper-input
I've tried it out and it works fine. Some better form support would be cool, but oh well. This stuff still kind of rocks.
UPDATE: I've built a bower package (polymer-rails-forms) to deal with forms in polymer, tailored specifically to the ActiveRecord input naming scheme but it will work with any old form really. It's still relatively new, but it covers most input types, basic validations, xhr and non-xhr submits and has a couple cool extras like image, json, and location* fields.
the location fields depend on the Google Map Places API

HTML5 Validation - PHP Form Action Attribute Empty

I was just validating some of my html5 pages on W3C with forms (PHP) on them and I get the following validation error:
Error: Bad value for attribute action on element form: Must be non-empty.
I thought that when the form submits to itself, it is good practice to leave the action attribute empty. Is this not the case? How can I fix this?
Thank you!
Simply put in "#".
<form action="#" method=post>
While browsers currently support the empty action since the spec says it's needed browsers in the future may not support it. In my opinion this is unlikely but you never know.
The reason I would add the action attribute is so if there is JavaScript somewhere that is actually posting the form the next developer in line is certain that this is were the form posts to and doesn't have to look though the relevant JavaScript files to see if this is intended or left out on mistake.
It can be fixed my putting the current page in the action attribute.
Hope that helps.

Zend Form renders an element with required="" which then is interpreted as required by the newest versions of browsers

Even when an element of Zend Framework has no setRequired() or has setRequired(false) called it is always rendered as <input ..... required="">
And seeing this code Chrome, Firefox and other newest versions of browsers while trying to validate the form before posting it, show the error message that the field is required (although it is not). It seems the browser detects the presence of the attribute required and does not care about its value (empty in this case).
Additionally, I tried <form novalidate="novalidate" ...> to ignore the browser validation but it did not work (anyway it would not be a good solution as one might still need to keep that browser side validation).
So, the question is how to make ->setRequired(true) to render required="required" and the lack of ->setRequired() or ->setRequired(false) not to render any attribute?
the ->setRequired(true) is only for the server side validation. to add the HTML5 required I use this
->setAttrib('required','true')
This will add required="true" which is not really necessary a simple required would be sufficient. But I never found a way to do that in Zend
In the input tag "required" attribute is a HTML5 attribute,not sure that Zend supports that.
You can set required it easily by using "->setRequired(true)" where you are declaring form elements by extending zend_form.

Browser offering to save passwords on HTML FORMS?

I have a sign up page on my website. Now when a user signs up, the broswer will offer to remember the password and email on the sign up form. Which is not what I want at all, as I only want it where they will login.
Is there anyway to disable this, or is it out of my control.
<input type="post" autocomplete="off" />
autocomplete does not work.
Thanks,
You're setting the attribute on the <input> element - this should be an attribute of the <form> element.
A number of solutions can be found here:
Disable browser 'Save Password' functionality
Your best bet is probably using JavaScript to bypass the default form submission mechanism.
There isn't a completely bulletproof way to turn autocomplete off.
autocomplete is a non-standard tag. So YMMV depending on the browser.
Try setting the attribute on the form tag instead of the input tag. I've had it work when specified on the form tag in the past.