If you’re new to validating forms, the code below simply goes through the array and checks it against our rules for each field.
Of course, if there’s no errors – the form does a hard .submit() – to the same processing page and handled accordingly.
Of course, we have add our styling so our field will look like our screenshots above. Again, the styles are real basic and you probably want to do better in your own forms. We’ve combined best of both worlds: server side and client side validation in one solution (thanks to Ajax). If a field validation rule has to change – we only need to change it in one place: the server code.
Note that in our case – I’m simply checking if first name and email is empty.
Of course in the real world, you will have to check for valid email and such.
But for the sake of our tutorial, I want to make it short and concise.
I prefer to write j Query, so the code below will only work if j Query is included.
The code below is to be added to our form page: Plenty of things going on above.
In any web application user data must be translated from HTML form data to native types and database types, and back again. The "right way" to handle custom types is to extend Django's widgets, form fields and model fields.
However, understanding exactly how these types perform each step of the conversion can be confusing.