2
votes

I've been reading and finding a solution for this problem since hours now. But it seems that I can't really fix this error. I found out that only when I add the form in FOS/UserBundle/Form/Type/RegistrationFormType that's the only time where it shows in the twig. I think I'm having some problem calling for my UserBundle/Form/RegistrationFormType. Badly need help on this one.

I'm using FOSUserBundle

Here's my User class:

<?php

namespace UserBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(name="first_name", type="string", length=255, nullable=false)
 * @Assert\NotBlank(message="Please enter your first name", groups={"Registration", "Profile"})
 */
protected $firstName;

/**
 * @ORM\Column(name="middle_name", type="string", length=255, nullable=false)
 * @Assert\NotBlank(message="Please enter your middle name", groups={"Registration", "Profile"})
 */
protected $middleName;

/**
 * @ORM\Column(name="last_name", type="string", length=255, nullable=false)
 * @Assert\NotBlank(message="Please enter your last name", groups={"Registration", "Profile"})
 */
protected $lastName;

/**
 * @ORM\Column(name="position", type="string", length=255, nullable=false)
 * @Assert\NotBlank(message="Please enter your position/title", groups={"Registration", "Profile"})
 */
protected $position;

/**
 * @ORM\Column(name="gender", type="string", length=255, nullable=false)
 * @Assert\NotBlank(message="Please chose your gender", groups={"Registration", "Profile"})
 */
protected $gender;

/**
 * @ORM\Column(name="birth_date", type="string", nullable=true)
 */
protected $birthDate;

/**
 * @ORM\Column(name="address", type="string", length=255, nullable=true)
 */
protected $address;

/**
 * @ORM\Column(name="school", type="string", length=255, nullable=true)
 */
protected $school;

/**
 * @ORM\Column(name="hired_date", type="string", nullable=false)
 */
protected $hiredDate;

/**
 * @ORM\Column(name="end_date", type="string", nullable=false)
 */
protected $endDate;

// Change the targetEntity path if you want to create the group

/**
 * @ORM\ManyToMany(targetEntity="UserBundle\Entity\Group")
 * @ORM\JoinTable(name="fos_user_user_group",
 *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
 * )
 */
protected $groups;

public function __construct()
{
    parent::__construct();

}

/**
 * @return String
 */
public function getFirstName()
{
    return $this->firstName;
}

/**
 * @return String
 */
public function getMiddleName()
{
    return $this->middleName;
}

/**
 * @return String
 */
public function getLastName()
{
    return $this->lastName;
}

/**
 * @return String
 */
public function getPosition()
{
    return $this->position;
}

/**
 * @return String
 */
public function getGender()
{
    return $this->gender;
}

/**
 * @return String
 */
public function getBirthDate()
{
    return $this->birthDate;
}

/**
 * @return String
 */
public function getAddress()
{
    return $this->address;
}

/**
 * @return String
 */
public function getSchool()
{
    return $this->school;
}

/**
 * @return String
 */
public function getHiredDate()
{
    return $this->hiredDate;
}

/**
 * @return String
 */
public function getEndDate()
{
    return $this->endDate;
}

/**
 * @param String $firstName
 * @return User
 */
public function setFirstName($firstName)
{
    $this->firstName = $firstName;

    return $this;
}

/**
 * @param String $middleName
 * @return User
 */
public function setMiddleName($middleName)
{
    $this->middleName = $middleName;

    return $this;
}

/**
 * @param String $lastName
 * @return User
 */
public function setLastName($lastName)
{
    $this->lastName = $lastName;

    return $this;
}

/**
 * @param String $position
 * @return User
 */
public function setPosition($position)
{
    $this->position = $position;

    return $this;
}

/**
 * @param String $gender
 * @return User
 */
public function setGender($gender)
{
    $this->gender = $gender;

    return $this;
}

/**
 * @param String $birthDate
 * @return User
 */
public function setBirthDate($birthDate)
{
    $this->birthDate = $birthDate;

    return $this;
}

/**
 * @param String $address
 * @return User
 */
public function setAddress($address)
{
    $this->address = $address;

    return $this;
}

/**
 * @param String $school
 * @return User
 */
public function setSchool($school)
{
    $this->school = $school;

    return $this;
}

/**
 * @param String $hiredDate
 * @return User
 */
public function setHiredDate($hiredDate)
{
    $this->hiredDate = $hiredDate;

    return $this;
}

/**
 * @param String $endDate
 * @return User
 */
public function setEndDate($endDate)
{
    $this->endDate = $endDate;

    return $this;
}
}

Here's My RegistrationFormType:

<?php

namespace UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('firstName', 'text', array('label' => 'form.first_name', 'translation_domain' => 'FOSUserBundle'))
            ->add('middleName', 'text', array('label' => 'form.middle_name', 'translation_domain' => 'FOSUserBundle'))
            ->add('lastName', 'text', array('label' => 'form.last_name', 'translation_domain' => 'FOSUserBundle'))
            ->add('position', 'text', array('label' => 'form.position', 'translation_domain' => 'FOSUserBundle'))
            ->add('gender', 'text', array('label' => 'form.gender', 'translation_domain' => 'FOSUserBundle'))
            ->add('birthDate', 'date', array('label' => 'form.birth_Date', 'translation_domain' => 'FOSUserBundle'))
            ->add('address', 'text', array('label' => 'form.address', 'translation_domain' => 'FOSUserBundle'))
            ->add('school', 'text', array('label' => 'form.school', 'translation_domain' => 'FOSUserBundle'))
            ->add('hiredDate', 'date', array('label' => 'form.hired_date', 'translation_domain' => 'FOSUserBundle'))
            ->add('endDate', 'text', array('label' => 'form.end_date', 'translation_domain' => 'FOSUserBundle'))
        ;
    }

    public function getParent()
    {
        return 'fos_user_registration';
    }

    public function getName()
    {
        return 'user_registration';
    }
}

Here's my services.yml:

services:
    app.form.registration:
        class: UserBundle\Form\RegistrationFormType
        tags:
            - { name: form.type, alias: user_registration }

Here's my config.yml:

fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
group:
    group_class: UserBundle\Entity\Group
profile:
    form:
        type: UserBundle\Form\ProfileFormType 
registration:
    form:
        name: user_registration

Here's my twig: I wanna call all the other entities I made

{{ form_widget(form.first_name) }}
{{ form_widget(form.last_name) }}
{{ form_widget(form.middle_name) }}
// and so on...
1
did the solution cleared your problem ?t-n-y

1 Answers

4
votes

call it like that : {{ form_widget(form.firstName) }}

In your form, it's firstName, not first_name. Same for lastname middlename ...