I am trapped with custom cck validation in my content type

I have a float price field, if i add space in the price field Drupal say confidently the field is not valid, i want to add function to remove the space before the default drupal cck validation, could anybody help

i tried with form alter and adding a validation handler but that is failing.

my form id is trade_result_node_form and the form alter contain the following code

case 'trade_result_node_form':
$form['#validate'][] = 'bz_custom_traderesult_form_validate';
$validate_array = $form['#validate'];
$validate_reversed = array_reverse($validate_array);
unset($form['#validate']);
$form['#validate'] = $validate_reversed;
break

function bz_custom_traderesult_form_validate($form, &$form_state) {
$form_state['values']['field_trade_entry_price'][0]['value'] = trim($form_state['values']['field_trade_entry_price'][0]['value']);
}

Thanks for reading the post

Comments

nikitas’s picture

if your custom module name is for example 'validator'
i think that your module name is bz but anyway you could replace the
validator_bz with bz ( dont forget the leading _ when its needed )
then inside your validator.module file you should have :

<?php
function validator_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'trade_result_node_form') {
// You should NOT have a [] value here
// plus you should protect your validation function by adding _ in front of the func name
$form['#validate'] = array('_validator_bz_custom_traderesult_form_validate');
}

// For testing the values you should then add
function _validator_bz_custom_traderesult_form_validate($form,&$form_state) {
$trim_this=trim($form_state['values']['field_trade_entry_price'][0]['value']);
$form_state['values']['field_trade_entry_price'][0]['value']=$trim_this;
}