Hi I'm trying to add new field (Telephone) to my FOS User bundle registration form. But Instead of getting this field I'm having this issue.
Method "telephone" for object "Symfony\Component\Form\FormView" does not exist in FOSUserBundle:Registration:register_content.html.twig at line 32
I'm trying to override custom templates and add new telephone field(Needed to customise to add few styles....). \app\Resources\FOSUserBundle\views\Registration\register_content.html.twig
This is my 'register_content.html.twig' template,
{% trans_default_domain 'FOSUserBundle' %}
<div class="container">
<h1 style="text-align: center;">Register a User</h1>
<br>
{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register form-horizontal'}}) }}
{# {{ form_widget(form) }}#}
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-4">
{{ form_widget(form.username, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors(form.username) }}
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-4">
{{ form_widget(form.email, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors(form.email) }}
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Telephone</label>
<div class="col-sm-4">
{{ form_widget(form.telephone, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors(form.telephone) }}
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-4">
{{ form_widget (form.plainPassword.first, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors (form.plainPassword.first) }}
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-4">
{{ form_widget (form.plainPassword.second, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors (form.plainPassword.second) }}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-default" value="{{ 'registration.submit'|trans }}" />
</div>
</div>
{{ form_end(form) }}
</div>
And this is my User Entity,
<?php
// src/AppBundle/Entity/User.php
namespace AdminBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="telephone", type="text", length=30, nullable=false)
*/
private $telephone;
/**
* Set nonotification
*
* @param text $telephone
* @return User
*/
public function settelephone($telephone) {
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* @return text
*/
public function gettelephone() {
return $this->telephone;
}
public function __construct() {
parent::__construct();
// your own logic
}
}