How to make form_rest() not display a field with Symfony2?
Another option is to explicitly mark the field as rendered:
{% do form.contenu.setRendered %}
How to render form_rest() as hidden fields in Symfony2/Twig?
You have to do it in you buildForm function, inside the "FormController". Just adding 'hidden' when you add the field is enough.
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name');
$builder->add('email', 'email');
$builder->add('subject');
$builder->add('anyone', 'hidden');
}
form_rest command showing previously-rendered Collection field
This seems like a bug in the form rendering. I managed to disable the extra form rendering in the form_rest function, by adding this code just after rendering the collection elements:
{% do form.uploads.setRendered() %}
Where "uploads" is my collection field type.
This doesn't seem like best practice to me though.
So the whole rendering looks like this:
<div id="uploads" data-prototype="{{ form_widget(form.uploads.vars.prototype)|e }}">
{% for upload in form.uploads %}
{{ form_widget(upload) }}
{% endfor %}
</div>
{% do form.uploads.setRendered() %}
Form in Symfony is fully displayed, instead of just some parts?
form_end()
also outputs form_rest()
, which renders all fields that have not yet been rendered for the given form: http://symfony.com/doc/current/reference/forms/twig_reference.html#form-rest-view-variables
If you don't want to render the unrendered fields, add {'render_rest': false}
to form_end
:
{{ form_end(form, {'render_rest': false}) }}
Render form without value in Symfony2
You could modify your entity in order to do this:
class MyEntity{
const DEFAULT_FOO = "Default value";
// ...
private $foo;
// ...
public function setFoo($foo){
if ( $foo === null ){
$foo = self::DEFAULT_FOO;
}
$this->foo = $foo;
}
// ...
}
And then make sure that you set by_reference
in order to ensure setter is being invoked each time:
$builder->add('field', 'text', array(
'by_reference' => true
));
How do you hide labels in a form class in symfony2?
Since Symfony 2.2 you can avoid the <label>
rendering using the false
value for the label
attribute:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('Name', null, array('label' => false))
;
}
Source
Related Topics
Get the Values of 2 HTML Input Tags Having the Same Name Using PHP
Accessing Arrays Whitout Quoting the Key
Upload Multiple Images with Codeigniter
PHP Function with Optional Parameters
How to Backup MySQL Database in PHP
Difference Between Array_Push() and $Array[] =
Regex Matching Table Rows in HTML
Trying to Replace Parts of String Start with Same Search Chars
How to Implement a Bitmask in PHP
How to Efficiently Use Try...Catch Blocks in PHP
Generating Confirmation Code for an Email Confirmation
Where Clause in Insert Statement Using MySQL/Php
How to Deploy Correctly When Using Composer's Develop/Production Switch
PHP - Add Two Hours to Date Variable
Fastest Way to Extract a Specific Frame from a Video (Php/Ffmpeg/Anything)