symfony-forms

How to get data from a form in symfony2

喜夏-厌秋 提交于 2019-12-24 23:18:46
问题 I have a method : public function showCategoryAction($id, $page, Request $request){ $em = $this->getDoctrine()->getManager(); $repositoryProduct = $em->getRepository('ShopDesktopBundle:Product'); $aFilter = array(); $form = $this->get('form.factory')->createNamedBuilder('', 'form', null, array( 'csrf_protection' => false, )) ->setMethod('GET') ->add('minimPrice', 'text', array('mapped' => false, 'label' => 'De la :' , 'attr'=> array( 'placeholder'=>'Minim price', 'class'=>'form-control'))) -

Defining custom twig form block for errors rendering

夙愿已清 提交于 2019-12-24 11:41:36
问题 I'm trying to define a specific new block for form field errors rendering, keeping form_errors unchanged for common errors rendering. # Twig Configuration twig: debug: %kernel.debug% strict_variables: %kernel.debug% form: resources: - 'ApplicationMyBundle:Main:form/customFormTheme.html.twig' In customFormTheme.html.twig I overwrite a few blocks copied from form_div_layout.html.twig plus I added the folloowing new one. {% block field_errors %}{% spaceless %} {% if errors|length > 0 %} <ul

Default value for entity backed Date field in Symfony2 Form Builder

a 夏天 提交于 2019-12-24 11:29:33
问题 Okay, I've got the FormType described below. I use this Form class for both the create and edit forms. I decided to set a default date ( from_date and to_date below), using the data attribute in the options array. This does a great job of setting the default date, in fact, too good a job. It also overrides the existing date in the edit form, which is no good at all, really. How do I set a real 'default' value, as opposed to an 'always' value? <?php namespace TechPeople\InvoiceBundle\Form; use

Could not determine access type for property “translations” in Symfony 3.2.* with Sonata admin project and Sonata translation bundle

江枫思渺然 提交于 2019-12-24 07:56:33
问题 I have installed Sonata admin project in Symfony 3.2.* version. Components that are being used in my project from composer.json file are as following: composer.json file's package snippet "require": { "php": ">=5.5.9", "ext-pdo_sqlite": "*", "a2lix/i18n-doctrine-bundle": "^0.1.0", "a2lix/translation-form-bundle": "^2.1", "doctrine/doctrine-bundle": "^1.6", "doctrine/doctrine-cache-bundle": "^1.2", "doctrine/doctrine-fixtures-bundle": "^2.2", "doctrine/orm": "^2.5", "erusev/parsedown": "^1.5",

Repeat the same fields in a form

心已入冬 提交于 2019-12-24 07:49:09
问题 What is the best way of repeating the same form fields within a form? I'd like the user to submit multiple Name / Phone number rows. class contactType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name1', 'text') ->add('phone1', 'text'); ->add('name2', 'text') ->add('phone2', 'text'); ->add('name3', 'text') ->add('phone3', 'text'); ....etc } } Ideally, I would like the user to enter as many fields as he wants... 1- Is there a

Symfony form inheritance : Neither the property nor one of the methods exist

假装没事ソ 提交于 2019-12-24 04:08:09
问题 I have a nested form demand home child godfather demand is a parent and embed home which embed child and father (2 last forms are on the same level) In DemandeType I have: $builder ->add('date', 'datetype') ->add('name', 'text') //... ->add('home', 'home', array( 'mapped' => false, 'data_class' => 'AppBundle\Entity\Home', 'inherit_data' => true )) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Demand', )); } In

Symfony form inheritance : Neither the property nor one of the methods exist

ε祈祈猫儿з 提交于 2019-12-24 04:08:05
问题 I have a nested form demand home child godfather demand is a parent and embed home which embed child and father (2 last forms are on the same level) In DemandeType I have: $builder ->add('date', 'datetype') ->add('name', 'text') //... ->add('home', 'home', array( 'mapped' => false, 'data_class' => 'AppBundle\Entity\Home', 'inherit_data' => true )) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Demand', )); } In

Success handler not working after Symfony2 login

笑着哭i 提交于 2019-12-24 03:43:14
问题 The goal is to do something after authentication success in Symfony2. In order to do that I have extended AuthenticationSuccessHandlerInterface creating a service for the form login in order to be its success handler. Here is the firewall in the security.yml file (where the success handler is declared): firewalls: main: pattern: ^/ form_login: check_path: fos_user_security_check provider: fos_userbundle csrf_provider: form.csrf_provider success_handler: foo_user.component.authentication

Success handler not working after Symfony2 login

霸气de小男生 提交于 2019-12-24 03:43:07
问题 The goal is to do something after authentication success in Symfony2. In order to do that I have extended AuthenticationSuccessHandlerInterface creating a service for the form login in order to be its success handler. Here is the firewall in the security.yml file (where the success handler is declared): firewalls: main: pattern: ^/ form_login: check_path: fos_user_security_check provider: fos_userbundle csrf_provider: form.csrf_provider success_handler: foo_user.component.authentication

Symfony2.1 form date field: Argument 1 passed to … must be an instance of DateTime

荒凉一梦 提交于 2019-12-24 03:05:27
问题 My Entity: /** * @var \DateTime $publishedAt * * @ORM\Column(name="published_at", type="date") * * @Assert\Date() */ private $publishedAt; /** * Set publishedAt * * @param \DateTime $publishedAt * @return MagazineIssue */ public function setPublishedAt(\DateTime $publishedAt) { $this->publishedAt = $publishedAt; return $this; } /** * Get published_at * * @return \DateTime */ public function getPublishedAt() { return $this->publishedAt; } My form builder: $builder->add('publishedAt'); My view: