Drupal: Custom Content Type validation - 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

Related

Laravel Nova - How can i do custom logic on Create/Update

I would like to create custom Create/Update logic for one of my Nova Resource. I have been thinking to use Custom Tools to accomplish what i wanted, but i don't want to give up the excellent work in the Index page and rewrite it all myself.
My use case:
I want to have an input that can define how many record to be created recursively.
I want to have morphToMany selection input in the form.
If you want to use different components on the index vs form/detail page just use the hideFromIndex and onlyOnIndex functions.
Detailed reference to docs: https://nova.laravel.com/docs/1.0/resources/fields.html#showing-hiding-fields
If you want to build repetitive fields, you can use the package: https://packagist.org/packages/fourstacks/nova-repeatable-fields

Only Comma separated values in textbox Symfony2

I have a text box on my form. I want only a comma separated keyword in that. How to put this type of validation in symfony2.
I found
http://symfony.com/doc/current/reference/constraints.html
and
http://symfony.com/legacy/doc/forms/1_2/en/02-form-validation
but not as I required.
well the validation logic is as simple as
if(is_array(explode(",",$input)){
return true;
}else{
return false;
}
use a custom validator and implement this logic
You should write your custom validator for check this requirements, then you can implements a data transformer so you can manipulate your string as you want. As example, if you are archiving something like a tagging field you can proceed as described.
In the client side you can add a js component that can do this behaviour for you, check this component in the Tagging support section (you can build a REST service for manage a subset of filed).
Let me know if this is your scenario so i can provide example code about.
Hope this help.

Get list of Assert Constraints in FormType Extension in Symfony2.1

I'm trying to implement client side form validation with javascript and I'd like to use the Validation defined in the Entity or the Form by putting them in the fields data- property.
The problem is that I don't know nor find any information about how to get the constraints from within the FormType extension.
I thought that the FormBuilder should have access to the data as it is used to start validation, but there doesn't seem to be any method to retrieve constraints.
Thanks for any help
You can use:
$validators = $form->getConfig()->getValidators();
on your form object
Finally I found a solution. It may not be the best, but serves for me.
I injected the Validator service into the FormTypeExtension.
Then I could do
$this->validator->getMetadataFactory()->getClassMetadata($options['data_class']);
I also had to change the service alias from "field" to "form" to get the data_class in options.
Hope this helps someone having the same problem.
If needed I can publish more details.

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

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.

How do you validate an archetype field that is not required, but if you give it, you should validate?

Products.validation has some validators (like regex) that I would like to use in some non required fields.
So, the use case is: The validation is required, but only if the field is not empty.
How do you do it? I know I can create a custom validator, check the REQUEST and do all the magic, but this seens wrong to me: I should avoid creating custom code since I should just register the RegexValidators from Products.validation and use it. I tried to understand V_SUFFICIENT and register a regex validator using it, but isn't applicable to my situation.
I couldn't find anything on the internet, on mailing lists, on nabble, etc. So, how do you validate your fields that aren't required, but if the user provides something, you then need to validate?
I need this in a Plone 3.3.5 instance.
You can use required = False and your desired validators:
http://plone.org/documentation/manual/developer-manual/archetypes/fields/fields-reference#common-field-attributes

Resources