What might be causing double requests to PHP?

2

I'm developing a system in Symfony2 and during the approval process the client caught an error in which the system alerts keep repeating.

The code used is this:

$objManager     = $this->getDoctrine()->getManager();
$objRepositorio = $objManager->getRepository( 'CIDSegurancaBundle:Usuario' );
$objUsuario     = $objRepositorio->find( $id );

if ( !$objUsuario ) {
  throw $this->createNotFoundException( 'Usuario nao encontrado para id ' . $id );
}

$objUserType = new UsuarioType( $objManager );
$objUserType->setIsEdit( true );
$objUserType->setUrlListagem( $this->generateUrl( 'usuarioListar', [ 'page' => 1, 'manterFiltro' => true ] ) );
$objUserType->setUrlListarEG( $this->generateUrl( 'usuarioAjaxListarEG' ) );
$objUserType->setUrlListarProcessos( $this->generateUrl( 'processoAjaxListarByMacroProcesso' ) );
$objUserType->setUrlListarSubProcessos( $this->generateUrl( 'subProcessoAjaxListarByProcesso' ) );

$objForm = $this->createForm( $objUserType, $objUsuario, [ 'attr' => [ 'id' => 'formUsuario' ] ] );

$objForm->handleRequest( $request );

$objUsuarioLogado = $this->getUser();
$objUsuario->setUsuarioAlteracao( $objUsuarioLogado );
$objUsuario->setDatAlt( System::getNow() );

if ( $objForm->isValid() ) {
  $objManager->persist( $objUsuario );
  $objManager->flush();

  $this->addFlash( 'info', 'Usuario alterado com sucesso!' );
  return $this->redirectToRoute( 'usuarioListar', [ 'page' => 1, 'manterFiltro' => 1 ] );
}

return $this->render( 'AppBundle:AcessControl:alterar.html.twig', [
  'title'  => 'Alterar Usuario',
  'form'   => $objForm->createView(),
  'perfis' => Perfil::getPerfisDisponiveis()
] );

The error I'm getting is that "FLASH" messages are appearing repeated on the following pages. When changing a user the client randomly receives the message: Usuário alterado com sucesso twice or even more.
The request is apparently being processed twice.

I did several local tests and could not reproduce the error in any way, so I'm guessing that this is related to some browser or client server configuration.

For approval, the customer is using Google Chrome 31.0.1650.57 m

Locally for testing I'm using Google Chrome '40 .0.2214.111 m

Does anyone have any idea what might be causing the problem?

Edition - 07/28/2015 at 08:30

alter.html.twig

{% extends 'AppBundle:util:form_cad.html.twig' %}
{% block javascript %}
  {% javascripts '@AppBundle/Resources/public/js/AcessControl/cadastro.js' output='js/usuario/cadastro.js' %}
  <script type="text/javascript" src="{{ asset_url }}"></script>
  {% endjavascripts %}

  <script type="text/javascript">
    window.perfil = {
    {% for nome, id in perfis %}
    {{ nome }}: '{{ id }}',
    {% endfor %}
    };
  </script>
{% endblock %}

form_cad.html.twig

{% extends 'AppBundle::base.html.twig' %}
{% form_theme form 'AppBundle:util:form.template.html.twig' %}
{% import "AppBundle:util:macro_form.html.twig" as macro %}

{% block conteudo %}
  {% spaceless %}
    <div class="col-md-12 col-lg-12">
      <div class="col-md-12 col-lg-10 col-lg-offset-1">
        <div class="panel panel-primary box-shadow-filter">
          <div class="panel-heading">
            <h3 class="panel-title text-center">{{ title }}</h3>
          </div>
          <div class="panel-body" id="formulario-cadastro">
            {% block panel_body %}
              {{ form_start(form) }}
              {{ form_widget(form) }}
              {{ form_end(form) }}
            {% endblock %}
          </div>
        </div>
      </div>
    </div>
  {% endspaceless %}
{% endblock %}

base.html.twig

{% spaceless %}
  <!doctype html>
  <html lang="pt-br">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}"/>

    <title>{% block title %} {{ project_name }} {% endblock %}</title>

    {% stylesheets 'bundles/app/css/bootstrap.min.css'
    '@AppBundle/Resources/public/css/jquery-ui/jquery-ui.min.css'
    '@AppBundle/Resources/public/css/jquery-ui/jquery-ui.theme.min.css'
    'bundles/app/css/bootstrap-theme.min.css'
    '@AppBundle/Resources/public/css/layout.css'
    '@AppBundle/Resources/public/css/sweetalert.min.css'filter='cssrewrite' output='css/main.css' %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
    {% endstylesheets %}

    {% block stylesheets %}{% endblock %}

    {% javascripts
    '@AppBundle/Resources/public/js/plugin/jquery-1.11.2.min.js'
    '@AppBundle/Resources/public/js/plugin/bootstrap.min.js'
    '@AppBundle/Resources/public/js/plugin/jquery-ui.min.js'
    '@AppBundle/Resources/public/js/plugin/jquery-mask.min.js'
    '@AppBundle/Resources/public/js/plugin/sweetalert.min.js'
    '@AppBundle/Resources/public/js/plugin/jquery.dataTables.min.js'
    '@AppBundle/Resources/public/js/util/modal.js'
    '@AppBundle/Resources/public/js/util/setup.js'
    '@AppBundle/Resources/public/js/util/util.js'
    '@AppBundle/Resources/public/js/util/processo.js'
    '@AppBundle/Resources/public/js/*.js'output='js/main.js' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}

    {% block javascript %}{% endblock %}
  </head>
  <body>
  {% block navbar %}
    {% block navbar_main %}

      <div class="navbar-main">
        <div class="col-md-2 text-center logo-top">
          {% block image_top %}
            <a href="{{ path('homeListar') }}">
              <img src="{{ asset('bundles/app/images/logo_cliente_azul.gif') }}"/>
            </a>
          {% endblock %}
        </div>

        <div class="col-md-3 text-center project-name">
          {% block project_name_top %}
            {{ project_name }}
          {% endblock %}
        </div>

        <div class="col-md-1 pull-right"></div>
        <div class="col-md-3 hidden-xs hidden-sm pull-right">
          {% block user_top %}
            {% if app.user is not null %}

              <div class="divFotoUsuarioLogado">
                {% set nome = app.user.nomUsuario|split(' ') %}
                <img class="img-circle" src="http://URL-REMOVIDA/foto/{{app.user.username}}.jpg"
                     title="" alt="" width="40" height="40"/>
              </div>
              <div class="divNomeUsuarioLogado">
                Ol&aacute;,<br/>
                <span class="text-uppercase">{{ nome[0] }}</span>
              </div>

            {% endif %}
          {% endblock %}
        </div>

      </div>
    {% endblock %}

    {% block navbar_menu %}
      {{ render(controller('AppBundle:Menu/Menu:accessMenu')) }}
    {% endblock %}

  {% endblock %}

  <div class="container-fluid">
    <div class="row">

    {% include 'AppBundle:util:session-alert.html.twig' %}

    {% block modal %}
      {{ include("AppBundle:util:modal-alert.html.twig") }}
    {% endblock %}

    {% block conteudo %}

    {% endblock %}
    </div>
  </div>

  </body>
  </html>
{% endspaceless %}
    
asked by anonymous 27.07.2015 / 22:56

1 answer

1

I noticed some form tags were empty. Properly placing the action on the forms has remedied the problem.

    
31.08.2015 / 20:47