I am trying to calculate a field based on whether or not a certain string exists at the end of the title field. For some reason, I cannot get substr() to work. It keeps returning the following error.
Fatal error: Cannot use string offset as an array in D:\EasyPHP3\www\drupal5\modules\computed_field-5.x-1.2\computed_field\computed_field.module(118) : eval()'d code on line 1
if (strpos($node->title[0]['value'], "-2")){
$node_field[0]['value'] = ($node->field_cfm[0]['value'])/400;
} else {
$node_field[0]['value'] = 0;
}I am working with http://drupal.org/project/node_import to batch import data. (Version 5.x-1.9)
Basically, I'm trying to check if the title ends with "-2". If it does, I want the computed field to be blank. If it doesn't, I want the computed field to be field_cfm/400.
Comments
Comment #1
washwithcare commentednevermind, i found the answer.
$node->title should be $node->field_title
Comment #2
washwithcare commentedactually, $node->title[0]['value'] should have been $node->title
whoops
Comment #3
doomed commentedDo you mind posting the final working code ?
Its always good to finish your threads like that. It will help others.
Comment #4
colanVersion 5 is no longer supported.