Umlauts not beeing displayed properly in symfony2 - symfony

Im having the following problem.
If I try to use this code
$form = $this->createFormBuilder()
->add('code', 'integer', array(
'attr' => array('class' => 'login-input')
))
->add('einlösen', 'submit', array(
'attr' => array('class' => 'login-submit')
))
->getForm();
my browser doesnt show the ö in einlösen.
If i remove the class attr it works.
I thought this might be a css issue but the problem seems to be with symfony, since there
is no matter what class I use the ö always gets mangled.
Another thing I realized is that if I do a cache clear the ö is there but as soon as i press the button once and reload the page its not showing up properly again.

Try to use the label option:
$this->createFormBuilder()
->add('submit', 'submit', array(
'label' => 'einlösen',
'attr' => array('class' => 'login-submit')
))
As an alternative you can set/overwrite the label in twig:
{{ form_widget(form.submit, { 'label': 'einlösen' }) }}

Related

How can I use the bootstrap-daterangepicker in symfony 3.4?

I try with the next code:
In the form builder
->add('daterange', DateType:class, array(
'widget' => 'single_text',
'attr' => ['class' => 'js-daterangepicker'],
'html5' => false,
))
And the javascript
$('.js-daterangepicker').daterangepicker({
});
This code works, but retrieve data invalid as validator result.
Is DateType the class? How do I recover the selected data in the widget?

Symfony2 Set translation domain for a whole form without a class

I want to translate a form created with symfony's formbuilder.
Now i have to specify the translation_domain for each form-field.
This option has to be added to every field and i'm wondering if there is a way to set this option to a whole form?
I need the solution for a form without a class. I know the solution for a Form Type Class.
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'translation_domain' => 'main'
));
This is my Code:
$form = $this->get('form.factory')->createNamedBuilder('shopChoiceForm')
->add('shops', 'entity', array('class' => 'AcmeBundle:Shop', 'choices' => $choices, 'translation_domain' => 'main'))
->add('submit', 'submit', array('label' => 'Choose', 'translation_domain' => 'main'))
->getForm();
You can specify translation domain in the twig at the moment you render your form. For doing so just use next code:
{% trans_default_domain "main" %}
It will change default translation domain to main. And it will influence only current template. If you want to render many forms in one template you can use form_theme tag and import theme with just this one line.
You can specify translation domain in the options array passed to the createNamedBuilder() as:
$form = $this->get('form.factory')->createNamedBuilder('shopChoiceForm', 'form', null, array('translation_domain' => 'main'))
->add('shops', 'entity', array('class' => 'AcmeBundle:Shop', 'choices' => $choices))
->add('submit', 'submit', array('label' => 'Choose'))
->getForm();

email collection (from book), submit buttons collection

I have a problem with collection from symfony documentation. Here is my code:
controller:
$emails = array("first#qwe.com", "second#qwe.com", "third#qwe.com");
$myDForm = $this->createFormBuilder($emails)
->add('emails', 'collection', array('type' => 'email', 'options' => array('required' => false, 'attr' => array('class' => 'email-box')),))
->GetForm();
$myDForm->handleRequest($request);
twig:
{{ form_start(myDForm) }}
{{ form_end(myDForm) }}
As you can see the code looks easy, there are no errors just an empty page...
Could somebody point me where is the problem? I'm a beginner but it's almost exact as code in doc.
I'd like to make several submit buttons on a form this way but I stuck with this.
Thank you.
First:
Change
GetForm
to
getForm
$emails = array("first#qwe.com", "second#qwe.com", "third#qwe.com");
$myDForm = $this->createFormBuilder($emails)
->add(
'emails',
'collection',
array(
'type' => 'email',
'options' => array('required' => false, 'attr' => array('class' => 'email-box')),)
)->getForm();
$myDForm->handleRequest($request);
I don't know what is your point to use emails with collection.
Second:
You are just opening your form. You are not giving any field to print.
{{ form_start(myDForm) }}
{{ form_row(form.emails) }}
{{ form_end(myDForm) }}
http://symfony.com/doc/current/reference/forms/twig_reference.html

Zend Form Decorators to embed label and elements

I have absolutely no idea how to use the decorators in Zend!
If you create a basic straightforward form without decorators, the labels go in DT and the elements go into DD. And they all go one after another.
So how do I make it so that each label and its corresponding element also go inside a div?
Thanks so much!
Kousha
I love decorators! But they are extremely hard to master. Its a good thing your questions is an easy one.
I use a function this in my forms
public function getElementDecorators()
{
return array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'class' => 'description')),
array('HtmlTag', array('tag' => 'dd', 'id' => array('callback' => array(get_class($this), 'resolveElementId')))),
array('Label', array('tag' => 'dt')),
array(array('elementContainer' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element-container')),
);
}
then for each of my elements in the form I create them like so.
$this->addElement('Text', 'wordup', array(
'label' => 'Put your words here',
'attribs' => array('class' => 'textbox-fancy'),
'decorators' => $this->getElementDecorators()
));

symfony2 EWZRecaptchaBundle extra Fields

I have a problem with the EWZRecaptcha Bunlde (dev-master) and symfony 2.1.0.
The reCaptcha is displayed correctly and the image changes so i think the configuration is ok. But the reCaptcha is not validated and after submitting, $form->getErrorsAsString() says: This form should not contain extra fields.
Well, i think the extra fields are recaptcha_challenge_field and recaptcha_response_field that are sent from reCaptcha but i don think that i missed something in the docu so what can be wrong with them?
For validation i use the code from the docu: (i also tried the alternative, that was mentioned there)
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha;
//...
/**
* #Recaptcha\True
*/
public $recaptcha;
//...
in config:
framework:
validation: { enable_annotations: true }
i added the field like this:
$builder->add('recaptcha', 'ewz_recaptcha', array(
'property_path' => false,
'attr' => array(
'options' => array(
'theme' => 'clean'
)
)
));
Maybe i forgot something essential, that was not mentioned in the docu?
Possibly try adding a 'constraints' option to the builder. My recaptcha builder add looks like this:
$builder->add('recaptcha', 'ewz_recaptcha', array(
'attr' => array(
'options' => array(
'theme' => 'red'
)
),
'label' => "Verification",
'property_path' => false,
'constraints' => array(
new True()
),
'help' => "Enter the words in the box for verification purposes."
));
So add a 'use' statement for the constraint:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True;
and then add the constraint option:
'constraints' => array(
new True()
),
finally found the solution!
to get rid of the extra fields i added those two fields in my form class:
$builder->add('recaptcha_challenge_field', 'hidden', array('property_path' => false));
$builder->add('recaptcha_response_field', 'hidden', array('property_path' => false));
the validation then works with:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True;
...
'constraints' => array(
new True()
)
the annotation doesn`t work for me:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints AS Recaptcha;
...
/**
* #Recaptcha\True
*/
public $recaptcha;

Resources