Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony][Symfony2] Własne komunikaty błedów w formularzu, Błedy domyślne zamiast wlasnych
radoslawchojnack...
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 2.01.2014

Ostrzeżenie: (0%)
-----


Witam

Jak w temacie nie działają komunikaty błędów. Pojawiają się tylko domyślne. Mam to zrobione tak:

  1. /**
  2.   *
  3.   * @ORM\Column(name="mail", type="string", length=255)
  4.   * @Assert\Email(
  5.   * message = "Wartość '{{ value }}' to nie jest email.",
  6.   * checkMX = true
  7.   * )
  8.   */
  9. private $mail;


Pojawia się komunikat "Proszę wprowadzić adres email"

Ten post edytował radoslawchojnacki@tlen.pl 2.01.2014, 22:35:14
Go to the top of the page
+Quote Post
Crozin
post
Post #2





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Jesteś pewien, że nie jest to wina cachea?

PS. Parametry name, type oraz length przy adnotacji Column są zbędne - domyślnie zostaną wybrane właśnie takie wartości.
Go to the top of the page
+Quote Post
radoslawchojnack...
post
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 2.01.2014

Ostrzeżenie: (0%)
-----


Cache w SF2 wyczyszczony oraz histoia przeglądarki wywalona.
Jakieś inne pomysly ?
Go to the top of the page
+Quote Post
pyro
post
Post #4





Grupa: Zarejestrowani
Postów: 2 148
Pomógł: 230
Dołączył: 26.03.2008

Ostrzeżenie: (0%)
-----


Sf sprawdza constrainty tylko dla wprowadzonych danych. Dla pustych danych potrzebny jest jeszcze NotBlank().

Jeżeli wprowadzasz dane to stawiam na cache albo nieprawidłowe przypisanie danych do entity, podałeś za mało kodu.


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
Go to the top of the page
+Quote Post
radoslawchojnack...
post
Post #5





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 2.01.2014

Ostrzeżenie: (0%)
-----


OKI

Oczywiście chodzi mi o komunikat dla wprowadzonych danych.


  1. namespace Blog\FrontendBundle\Controller;
  2.  
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8. use Blog\BackendBundle\Entity\Email;
  9. use Blog\BackendBundle\Form\EmailType;
  10.  
  11.  
  12. class SubscribeController extends Controller
  13. {
  14.  
  15. /**
  16.   * Creates a new Email entity.
  17.   *
  18.   * @Route("/", name="subscribe_create")
  19.   * @Method("POST")
  20.   * @Template("BlogBackendBundle:Email:new.html.twig")
  21.   */
  22. public function createAction(Request $request)
  23. {
  24. $entity = new Email();
  25. $form = $this->createCreateForm($entity);
  26. $form->handleRequest($request);
  27.  
  28. $validator = $this->get('validator');
  29. $errors = $validator->validate($entity);
  30.  
  31. if ($form->isValid()) {
  32. $em = $this->getDoctrine()->getManager();
  33. $em->persist($entity);
  34. $em->flush();
  35.  
  36. return $this->redirect($this->generateUrl('subscribe_ok'));
  37. }
  38.  
  39. return array(
  40. 'entity' => $entity,
  41. 'form' => $form->createView(),
  42. );
  43. }


  1.  
  2. namespace Blog\BackendBundle\Form;
  3.  
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  7.  
  8. class EmailType extends AbstractType
  9. {
  10. /**
  11.   * @param FormBuilderInterface $builder
  12.   * @param array $options
  13.   */
  14. public function buildForm(FormBuilderInterface $builder, array $options)
  15. {
  16. $builder
  17. ->add('mail')
  18. ->add('fulname', null, array('required' => false) )
  19. ->add('www', null, array('required' => false))
  20. ->add('aboutUser', null, array('required' => false))
  21. ->add('country', null, array('required' => false))
  22. ->add('city', null, array('required' => false))
  23. ->add('interest', null, array('required' => false))
  24. // ->add('created')
  25. // ->add('updated')
  26. ;
  27. }
  28.  
  29. /**
  30.   * @param OptionsResolverInterface $resolver
  31.   */
  32. public function setDefaultOptions(OptionsResolverInterface $resolver)
  33. {
  34. $resolver->setDefaults(array(
  35. 'data_class' => 'Blog\BackendBundle\Entity\Email'
  36. ));
  37. }
  38.  
  39. /**
  40.   * @return string
  41.   */
  42. public function getName()
  43. {
  44. return 'blog_backendbundle_email';
  45. }
  46. }


i formularzyk

  1. {{ form_start(form) }}
  2. {{ form_errors(form) }}
  3.  
  4. {{ form_row(form.mail) }}
  5. {{ form_errors(form.mail) }}
  6.  
  7. {{ form_row(form.fulname) }}
  8. {{ form_row(form.www) }}
  9. {{ form_row(form.aboutUser) }}
  10. {{ form_row(form.country) }}
  11. {{ form_row(form.city) }}
  12. {{ form_row(form.interest) }}
  13.  
  14. <input type="submit" value="Dodaj subskrypcję" />
  15. {{ form_end(form, {'render_rest': false}) }}


Hmm, w sumie to nie wiem co jeszcze. może tak same rególy mi działają czyli jak dałem sobie na próbę @Assert\Blank to reguła zadziałała. tylko massage nie chce dzialać.
Nie mogę nic zaóważyć.

Ten post edytował radoslawchojnacki@tlen.pl 2.01.2014, 23:17:01
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 12:31