I've been at my wit's end for a few days now with this issue and I can't seem to find the problem.
Overview:
- I'm building a Symfony2 website using FOSUserBundle as the user manager, and Propel as the database provider.
- I've successfully overridden the login template and I can log in and out successfully from a modal view.
- I've added 6 custom fields to my schema.xml, and the model builds correctly (ie. I can query these fields in a tabulated User Manager).
- I can successfully register as a new user in the default route for registration on my overridden form, and the data shows up in my database as expected.
The Issue:
I have moved the registration form to its final position inside a modal view in my 'user manager dashboard'. My form loads and displays correctly, but for whatever reason refuses to submit data to the controller for processing. Instead it simply loads the default route for registration ('/register') and displays the form again but without any of my css, js, or base twig template. When I re-enter information in that form, it simply reloads with none of the info going in to the database.
I am convinced the issue lies in either (or both) how I am submitting the form or how I have classed the form.
Note I have changed the name of my classes to the statutory AcmeBundle for obvious reasons :)
Can anyone shed some light on this? I am literally about to implode over this issue!
Thank you in advance :D
EDIT
I now think this could possibly be a routing issue as I have verified my form builds and collects all its values correctly?
app/config.yml
#FOS UserBundle Configuration
fos_user:
db_driver: propel # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: FOS\UserBundle\Propel\User
registration:
form:
type: acme_user_registration
#Services
services:
acme_user.registration.form.type:
class: Acme\UserBundle\Form\Type\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: acme_user_registration }
acme_user.form.handler.registration:
class: Acme\UserBundle\Form\Handler\RegistrationFormHandler
arguments: ["@fos_user.registration.form", "@request", "@fos_user.user_manager", "@fos_user.mailer", "@fos_user.util.token_generator"]
scope: request
app/routing.yml is standard FOSUserBundle config as per docs
# FOSUserBundle Routing
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
Acme/UserBundle/Controller/RegistrationController.php
<?php
namespace Acme\UserBundle\Controller;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
use Symfony\Component\HttpFoundation\Response;
class RegistrationController extends BaseController
{
public function render($view, array $parameters = array(), Response $response = null)
{
return parent::render($view, $parameters, $response);
}
}
Acme/AdminBundle/Resources/views/_addUser.html.twig this is where I call my modal in
{% include "FOSUserBundle::layout.html.twig" %}
<!-- Modal -->
<div id="registerUser" class="reveal-modal xlarge" data-reveal>
<h2 align="center">Add New User</h2>
<h6 align="center" style="color: red">All Fields are Required</h6>
{% block fos_user_content %}
{% render url('fos_user_registration_register') %}
{% endblock %}
<a class="close-reveal-modal">×</a>
</div>
app/Resources/FOSUserBundle/views/Registration/register.html.twig Overidden as per docs
{% block fos_user_content %}
{% include 'FOSUserBundle:Registration:register_content.html.twig' %}
{% endblock %}
app/Resources/FOSUserBundle/views/Registration/register_content.html.twig Overidden as per docs
<form data-abide class="fos_user_registration_register" action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="post" >
<fieldset>
<legend>Personal Details</legend>
{# First Name #}
<div>
<label for="form_first_name">First Name</label>
<input type="text" id="form_first_name" name="form[first_name]" required pattern="[a-zA-Z]+"/>
<small class="error">This field is required</small>
</div>
{# Last Name #}
<div>
<label for="form_last_name">Surname</label>
<input type="text" id="form_last_name" name="form[last_name]" required pattern="[a-zA-Z]+">
<small class="error">This field is required</small>
</div>
etc...
etc...
etc...
</fieldset>
<div>
<input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>
</form>
RegistrationFormHandleris injected with the@requestservice, but it might be better to inject this with@request_stackand then get the master request via$request = $requestStack->getMasterRequest();- Adam Elsodaney