08.
Error Formatting for Twitter Bootstrap
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
8 Comments
Hi there,
My form validation is working partially let alone bootstrap validation. Thanks in advance.
Hey Junaid Farooq!
So... do you mean that form validation IS working, but you don't see the bootstrap styles? Or something different? If so, if you view the HTML source, do you see classes like
form-groupandform-controlin your HTML, or not?Cheers!
Hey weaverryan
Thanks for replying. I meant my server side form validation is not working. No errors are shown. For example if i disable the front end validation and then try to submit an empty form, it doesn't validate the form from the server side instead it tries to insert the data into the database which then throws a db exception. I hope you get what i mean. Cheers!
Hey Junaid,
What validation constraints do you use? And where do you declare it? Because, by default, Symfony does not add some validation on the server side for empty fields, you need to add it by your own.
Cheers!
Hey victor
Thanks for replying. I am using the constraints in the User entity. Following is an example of sych for Username and email:
class User implements AdvancedUserInterface, \Serializable
..................
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255, unique=true)
* @Assert\NotBlank(message="Username cannot be empty")
* @Assert\Length(min=3, minMessage="Username should be at least 3 characters!")
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, unique=true)
* @Assert\NotBlank(message="Email cannot be empty")
* @Assert\Email
*
*/
private $email;
...................
Cheers!
Hey Junaid,
Hm, looks legitimate for me if you use the next namespace in User entity:
use Symfony\Component\Validator\Constraints as Assert;
So it really should work. Do you use "$form->isSubmitted() && $form->isValid()" in your controller? Well, try to clear the cache first and if you still have this problem, can you show your form type you use and a part of your controller which relates to this form?
Cheers!
Hey victor
Again Thank you for your prompt response. Back to your response. yes I am using the namespaces required in the User Entity. here are all of them:
To your question: Yes i am using "$form->isSubmitted().....".Here is the whole registerAction():
Here is my RegisterFormType code:
Please have a look and thank you once again for reaching out. Cheers!
Hey Junaid,
Hm, I see a few problems in your code which could cause this validation problems, so let me tweak your code to the best practice and if you're wondering about any changes I made - just ask another question ;) For simplicity, if I only change things of add new ones, so if I'm not sowing something in my code - this means it's the same as in yours.
So, first of all your need to bind RegisterFormType to the entity:
"Houston: no signs of life"
Start the conversation!