Jquery validator method not working if used multiple times in a form - jquery-validate

we are using a javascript form where a enduser has to enter phonenumber and promo code apart from other details. All the fields in the form are mandatory.
I am using validator.add(method) to validate phonenumber using regex.
Also using an another validator.add(method) to validate the promo code
But am able to use only one validator method. If am using multiple i.e., more than one, then the validation is not working.
Is the jquery validator method restricted to use only once in a form.
Please suggest me a solution for this.

You can use an OnSubmit function for the form and validate all the data there, you can also write several functions and use them in the main onsubmit function.

Related

Where i need to put validation code?

I have a form with a number of fields.
Some of them are userId, userFirstName, userLastName.
When user inputs incorrect userId value then near userId field page must show error message and add this error into validationSummary(this is standart behavior for asp.net mvc unobtrusive validation). If userId is correct then page must remove errors and autopopulate userFirstName and userLastName(This is not standart behavior)
How can i implement this?
Here is what come to my mind:
Remote validation attribute
It has a bad customization in my case. That's why i decide to don't use it.
Add special method for jquery validation plugin ( for example
jQuery.validator.addMethod("userIdValidation", function(value, element) {
//some logic
return something;
}, "Please specify the correct userId"); )
and put there logic for validation and for autopopulate other fields.
In this case i mix validation and other stuff.
3 . Add special method for jquery validation plugin ONLY for validation and add special handler for input change event for autopopulate.
In this case i need to send TWO ajax requests to server for one thing. And ofcourse it is not good too. So what is the right way? I am confused.
Have you thought about using a partial view to display the userFirstName and userLastName?
You can fire an AJAX request that sends the userId, and then returns a partial view of the name fields. Within the controller being called, you can validate the incoming userId, and then grab the name details in one query. If thevalidation fails, you can return the partial view with empty fields.

CodeIgniter Validation: possible to validate GET query strings?

The form validation library seems to only work on POST. I need to use query strings and would like to use CI to validate the passed values. Is there a way to do this?
The current Codeigniter 3.0 development branch provides an option to insert your own variable instead of $_POST. So you could start using 3.0.
Alternatively, the only way in CI2.1 is to do $_POST=$_GET before you run the validation.
See this page for the CodeIgniter 3 solution:-
http://www.codeigniter.com/userguide3/libraries/form_validation.html#validating-an-array-other-than-post
For CodeIgniter 2 you can do $_POST = $_GET; before $this->form_validation->run() as mentioned above.
You could overwrite the Form_validation function run in a MY_Form_Validation and modify it.
Reference How do I validate a form field in Codeigniter when using Get parameters?
Before validation rules, set the validation data with the following code.
$this->form_validation->set_data($_GET);

jqgrid - validation of form data at entry time (or how do I get onblur events to bubble up?)

I am trying to do validation of entries via Ajax. I am validating if the information entered is valid Perl regexp before the user submits the data. Is there a way to use the onblur() event from the individual input field to do the validation?
Reading the docs it seems that I can override each event globally, but I want to be able to perform different checks for each input field. I also know there is the beforeSubmit() event, but that is generated too late for what I want to do.
I am using jqgrid 4.1.2.
Any help would be appreciated.
J

Validate data from CakePHP form with jQuery (AJAX)

I would like to validate both single field and multiple field data from a CakePHP form.
The single field validation should be done on blur from each field while the multiple field validation should be done on submitting the form.
I would like to use the $validate property declared in the Model for validating data and I would like to display the errors near each field (single field validation) and on top of the form (for multiple field validation).
My main goal is to achieve this the most "caky" way (if there is one for validating data with jQuery). I couldn't find any useful advice out there and I'm asking you for some help to get this going.
One of my concerns is how shall I pass data from the form to jQuery and then to the action that does the validation and also how shall I return and display the errors, if there are any.
Thank you in advance!
I'd suggest first making sure everything works without jQuery, then use the jQuery Form plugin to submit your forms via AJAX. If you include the RequestHandler component in your AppController, you should find that your controllers distinguish automatically between AJAX and synchronous requests.
OK, so I coded my own solution to this, but I am still waiting for a more "caky" approach.
I made two generic jQuery functions, one for single field validation and one for multiple field validation. The function should grab the data from the specified form and send it to the form's action via AJAX, to a specially created controller method which will attempt to validate data and output an AJAX response ("" for validation has passed and errors for errors in validation). Then, the result is checked in the jQuery function and the default form behaviour is triggered only if the validation has passed. Otherwise, display the errors and return false; to prevent default submission.

Drupal: Custom Content Type validation

I've created a custom content type with CCK.
If I need to add some custom code for validating fields of this content type's record form, where do I add the code and which functions are best for this task?
The easiest way would probably be hook_form_alter() and the #validation attribute on the form. You would of cause have to implement this in your own module.
The form api is what you use to validate, you'll be crafting your own validation function. I'm going to assume you are using D6
There's a less painful way:
http://drupal.org/project/validation_api
This module lets you make php code or regex for any given field.
Hope this helps.
To create your own module to implement form validation I suggest this method:
create a new module for content type field validation in drupal

Resources