Advertisement
Guest User

Exemple

a guest
May 4th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. /* Balise sans l'attribut action */
  2.  
  3. <form id="form_create_fiche" class="form_create_fiche" method="POST" {{ form_enctype(form) }}>
  4.  
  5. /* Contrôle du formulaire de fiche */
  6.  
  7. $(".form_create_fiche").validate({
  8.     rules: {
  9.         "caplab_fichesbundle_fiche[name]": {
  10.             required: true,
  11.             remote: {
  12.                     url: "{{ path('checkFiche')}}",
  13.                     type: "POST",
  14.                     data: {
  15.                         "caplab_fichesbundle_fiche[name]": function() {
  16.                             console.log($( "#caplab_fichesbundle_fiche_name" ).val());
  17.                             return $( "#caplab_fichesbundle_fiche_name" ).val();
  18.                         },
  19.                         fiche_user_id: function() {
  20.                             console.log("no");
  21.                             return $("#fiche_user_id").val();
  22.                         }
  23.                     }
  24.                 }
  25.         }
  26.     },
  27.     messages:{
  28.             "caplab_fichesbundle_fiche[name]":{
  29.                     remote: jQuery.validator.format("{0} est déjà utilisé.")
  30.                  }
  31.     },
  32.     errorPlacement: function(error, element) {
  33.             error.insertAfter(element.parent());
  34.     }
  35.  
  36. });
  37.  
  38. /* Action du formulaire */
  39.  
  40.     public function checkFicheAction()
  41.     {
  42.         $request = $this->container->get('request');
  43.         if($request->isXmlHttpRequest())
  44.         {
  45.             $user = '';
  46.             $name = '';
  47.             $name = $request->request->get('caplab_fichesbundle_fiche')['name'];
  48.             $user = $request->request->get('fiche_user_id');
  49.             $repository = $this->getDoctrine()
  50.                                 ->getManager();
  51.             //$cartes = $repository->getRepository('CapLabFichesBundle:Fiche')->getSortAlphaCartes($champ, $type, $mode, $this->getUser()->getId());
  52.             $fiche = $repository->getRepository('CapLabFichesBundle:Fiche')->findBy(array('user' => $this->getUser()->getId(), 'name' => $name));
  53.             if ($fiche)
  54.                 return new Response("false");
  55.             else
  56.                 return new Response("true");
  57.         }
  58.  
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement