Changing cck-field before validation, how?
yultyyev - July 12, 2009 - 16:51
Hi all!
Could somebody tell my what i'm doing wrong
I need allow user submit numeric cck-filed with 2 decimals separators - dot and comma (it made for usability)
So, I'm create cck-field width dot-separtor and just want to replace comma with dot in submitted values
I tried like this:
e.g. 2,6 rather 2.6
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'mynode_node_form') {
array_unshift($form['#validate'],'mymodule_myfield_mynode_node_form_validate');
}...
function mymodule_myfield_mynode_node_form_validate($form_id, &$form_state) {
$form_state['values']['field_myfield'][0]['value']=str_replace(',','.',$form_state['values']['field_myfield'][0]['value']);
}and see that 2,6 is incorrect, it looks like cck validation starts earlier
second try (without profit):
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if($node->type == 'mynode') {
switch ($op) {
case 'validate':
$node->field_myfield[0]['value']=str_replace(',','.',$node->field_myfield[0]['value']);
break;
...maybee I'm not advanced drupal coder, but I'm learn it...

How about using a field type with this feature builtin?
http://drupal.org/project/formatted_number