I've created a type of content with CCK, now I need to validate some inputs but I don't know how to do it, can you help me?

Comments

derhasi’s picture

Status: Active » Fixed

You have to create some PHP-Code for validation. On negative results you can create error messages with form_set_error(). In your code you can get acces on the field via $node. So is title set in $node->title, body in $node->body and any cck-field in $node->field_fieldname (like it is shown in the field listing of the content type).

You can find some code examples in the readme-File.

-----------------------------------------------------------------------------------------

Test minimum length of a textfield (e.g. 4 chars)
-------------------------------------------------
- Validiation Code:

if (strlen($node->field_text[0]['value'])<4){
  form_set_error('field_text','text has to have a minimum of 4 chars!');
}

- Process validation
can be set to both (field or widget)

Test date's year
----------------
- Validiation Code:

if ($node->field_date[0]['value']['year'] >= 2000){
  form_set_error('field_date','Date has to be before year 2000');
}

- Process validation
WIDGET - for this code it has to be set to widget, because in field-validation
date-array isn't present anymore.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

kenorb’s picture