I am working on grails project where I need to apply server side validations.
For client side validations I have created basic validation.js file which contains all the javascript functions.
Now what should be the ideal way to achieve the server side validation using Ajax, to achieve the validations like Record Duplication check.
Thanks in advance....
I'd recommend reversing your approach and using the Remote Constraints plugin: http://grails.org/plugin/remote-constraints
It lets you write your validation on the server side (as Domain class constraints) and then generate client side ajax validation so a message is shown when the user tabs off an input field.
cheers
Lee
I do it like this;
Create a controller with a method (closure) and call it using Ajax. It then returns map with a success false or true, and a optional msg. You than handle it in js code.
Generally, I don't like to post links to solutions but there is quite a bit of code involved so read my article here: http://groovy.dzone.com/articles/better-scaffolding-jquery-part-0
It will show you exactly how to do what you are wanting.
Related
I hope you are doing well.
I was wondering that is there any way to validate front end validation using codeigniter?
Basically I want to validate client side & server side validation using codeingiter.
Let me know if there's any pretty library or something.
I have searched on Internet and end up here to ask experts. :)
Many Thanks,
Muhammad Ahsan Ali
here is CI library with example!
https://codeigniter.com/user_guide/libraries/form_validation.html
A video link to understand
https://www.youtube.com/watch?v=axtmWvdFdDk
to custom rules
https://arjunphp.com/custom-validation-rules-codeigniter/
Check out this Code to make Ajax serve side validation showing in Client side
Ajax Validation in Codeigniter using Ajax
I recently try oforms module on orchard and I confess that I was expecting more.
My form not validating on IE8.
No ServerSide validation
No complex validation using Regex
Impossible to fill in dropdownlist options from a DB or an xml file
Impossible to set up workflows except e-mails
did I miss something that could change my opinion and make me buy this product ??
it does what it says it does. So it looks like a good module. Would be nice to have server side validation.
It works for me in IE8.
Im attempting one of my first web applications in PHP.
There is a text box a user inputs text and clicks send. When send is clicked or when they are typing I want it to give the user an error message if they are entering forbidden characters.
But I cant really see a way to do it effectively in PHP.
Can anyone tell me what programming language would be best for this and maybe links if that would help.
However, I do not want anyone to give me the complete code for this, otherwise there is no challenge in it for me.
Thanks guys
You can use Javascript (with or without jQuery) to realtime validation. Or you use PHP to a server-side validation with IF conditionals.
Javascript Validation Sample:
http://www.w3schools.com/js/js_form_validation.asp
-- EDIT --
I recommend you validate first in the Javascript and later in PHP, because with FireBug users can edit the Javascript validation script.
There are two kinds of validation you need to consider: client-side and server-side.
Client-side validation is when the browser checks the input and reports errors as the user types, or when they hit "submit". You will probably want to use Javascript for this.
Server-side validation is when the server checks the input after the browser has submitted it. You can check this in PHP (or whatever server-side language you want - Java, C# or whatever). Note that you must do server-side validation even if you also do client-side, because you can't trust the user to submit valid data. It's pretty easy to submit bad data even when client-side validation is in use.
You need to use JavaScript because it is a client side language and can detect changed as the user is typing and such.
What is the best way to do validation in MVC 3? Here are the requirements:
Works client and server side.
Shares as much code between client and server as possible (attribute on model property seems ideal)
Works across async request
Display errors, validation messages, and success messages coming from the server side
Unobtrusive javascript, as minimal as possible
Dynamically added HTML should still validate the same way
My task this weekend is to build a robust solution for this, figured I'd ask here first before re-inventing or re-discovering the wheel with blood sweat and tears.
I would check out Brad Wilson's blog on this. He covers using unobtrusive validation in MVC3, sounds like exactly what you're looking for.
Adding more info per OP's comment
Regarding server side validation (custom validation), check out #jfar's response to a similar question I posted regarding custom validation -- he suggests that you should question your design if you're relying heavily on custom validation. In my case, I ended up going either with Ajax to handle my custom validation, or allowed the postback to perform the validation.
Is there a way to have the same kind of client-side validation in MVC 3 without being able to set the validation at the viewmodel level?
I have two requirements that are preventing me from adding my validation at the viewmodel level. I'd like to be able to have the same kind of "built-in" validation but without changing the viewmodel or controller code. I'd like to be able to change, turn on/off, validation at the view level post-deployment. Ideally I'd like to be able to edit the view mark-up without writing and maintaining mountains of my own JavaScript.
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
This may help ya, only validation on the client though so not really ideal.
You could create your own TypeDescriptionProvider which will allow to augment your viewmodel at runtime.
Based on this code sample (XmlMetadataTypeDescriptor, XmlMetadataTypeDescriptionProvider) you should be able to:
Augment viewmodel using external xml which contains validation attributes.
Turn on validation with
TypeDescriptor.AddProvider
and turn it off with:
TypeDescriptor.RemoveProvider
Update
For more information you can read great article: "Understanding the TypeDescriptor: A Metadata Engine for Designtime Code".