symfony-forms

Apply class to Symfony2 Form Label

流过昼夜 提交于 2020-02-18 05:42:41
问题 I'm attempting to set the class on a class on a form label using php templates. Here's my code: <?php echo $view['form']->label($form['first_name'], 'First Name', array( 'attr' => array('class' => 'control-label') )) ?> But here's my output: <label class="required" for="form_first_name">First name</label> I can find how to do it using twig, but not an example with PHP. 回答1: I've got it... <?php echo $view['form']->label($form['first_name'], 'First Name', array( 'label_attr' => array('class' =

Skip validation if sibling (checkbox) field contains 'false'

爷,独闯天下 提交于 2020-01-29 13:23:29
问题 I have a form containing a checkbox and a "value field". The value field could be anything, a text box, a compound field, a collection - anything. The form could look like this, for example: field_1_label enabled [x] value [________] field_2_label enabled [x] value sub_field_1 [________] sub_field_2 [________] field_3_label enabled [x] value [________] When the "enabled" field contains true , everything works fine already. When the "enabled" field contains false , I would like to disable

Symfony2: Overriding a built-in field type with a custom field type having the same name

久未见 提交于 2020-01-24 15:26:39
问题 As per this article on the Symfony docs, I've created a custom field type, set it up in services.yml , and I am able to use it successfully. For example, I create a custom field named customdate as follows, which works perfectly: # src/Acme/DemoBundle/Resources/config/services.yml services: acme_demo.form.type.date: class: Acme\DemoBundle\Form\Type\DateType tags: - { name: form.type, alias: customdate } However, if I try to name my custom field as date (which is the same as an existing

Symfony2: Overriding a built-in field type with a custom field type having the same name

一曲冷凌霜 提交于 2020-01-24 15:19:09
问题 As per this article on the Symfony docs, I've created a custom field type, set it up in services.yml , and I am able to use it successfully. For example, I create a custom field named customdate as follows, which works perfectly: # src/Acme/DemoBundle/Resources/config/services.yml services: acme_demo.form.type.date: class: Acme\DemoBundle\Form\Type\DateType tags: - { name: form.type, alias: customdate } However, if I try to name my custom field as date (which is the same as an existing

How to have jquery to return csrf?

时间秒杀一切 提交于 2020-01-16 18:06:14
问题 Reading this Symfony CSRF and Ajax it just returns the csrf, but how should be the jQuery to return it to form? EDIT: My code is below: $formFactory = Forms::createFormFactoryBuilder() ->addExtension(new CsrfExtension($csrfManager)) ->getFormFactory(); $defaultFormTheme = 'bootstrap_3_layout.html.twig'; $vendorDir = realpath(__DIR__.'/../vendor'); $appVariableReflection = new \ReflectionClass('\Symfony\Bridge\Twig\AppVariable'); $vendorTwigBridgeDir = dirname($appVariableReflection-

How to fill the dropdown list dynamically in symfony? (select the cities of the region)

拜拜、爱过 提交于 2020-01-14 03:14:07
问题 I explain my problem: I have to create a form where the drop-down lists are filled according to our choices in the previous ones. I have two entities: A Region may have several Cities (ManyToOne) relationship. I followed the documentation from here How to Dynamically Modify Forms Using Form Events (Dynamic Generation for Submitted Forms) . Here is the code for the entities: Region entity: class Region { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue

Symfony2 : Radio buttons in a collection

最后都变了- 提交于 2020-01-12 04:36:04
问题 In my application, I created a form using the collection field type : $builder->add('tags', 'collection', array( 'type' => new TagType(), 'label' => false, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false )); With some JQuery, this code works correctly, but now I would like to select one of this dynamic tag to make it "the main tag". In my Tag entity, I added a boolean attribute which define if the tag is the main or not : /** * @ORM\Column(name="main", type="boolean") */

symfony2: setting the value of a form field outside the form, inside a controller action

蹲街弑〆低调 提交于 2020-01-10 08:59:13
问题 I need to set the value of a symfony2 form element. I use a doctrine2 entity, a Symfony\Component\Form\AbstractType and the createForm() method inside my Controllers Action. $saleDataForm = $this->createForm(new SaleType(), $sale); Now, how do i get an element from that form, and how can i set it's value? I want to do something like this, but it doesn't work: $saleDataForm->get('image')->setValue('someimapge.jpg'); FYI: I need to do this to render the field correctly (using this approach, my

Form requested url not found

99封情书 提交于 2020-01-07 02:21:23
问题 hello Im working on a symfony project. Im battleling with a form that wont redirect to its own page. the action attribute is set to "" and method set to post. In that case it should call the same page but im ending on a 404 page. here's the code of my page in the action file: public function executeDetail(sfWebRequest $request) { if($request->isMethod(sfRequest::POST)) { if(!$this->getUser()->isAuthenticated()) $this->redirect('@user_login'); $formData = $request->getParameter($this->form-

How to add an entry field dynamically in an empty collection form?

断了今生、忘了曾经 提交于 2020-01-06 02:59:04
问题 I am encountering an issue with my form and I need help... I want to create a form which can persist an advert. My issue come from my ManyToMany item 'images'. The new div i get by the 'images' form look like this: <div><label class="required">Images</label><div id="annonce_rent_images" data-prototype="<div><label class="required">__name__label__</label><div id="annonce_rent_images___name__"><div><label for="annonce_rent_images___name___url" class="required">Url</label><input type="url" id=