Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am creating a node programmatically and I have a field which is autocomplete and has number of values set to unlimited.

In the code for adding the node programmatically ,the code is as given below

    $node->field_user[]['value'] = $user->name;
       $node->field_time[]['value'] = date('m-d-Y H:i', REQUEST_TIME);
  $trans_node->field_download_flag[0]['value'] = 'YES';

So after programmatically creating a view when I check into the 'find content' place I see a node being generated but when I click on the link(where the content title is )( not on the edit link) , I cannot see the field_user in the view list

field_time
type: date
widget : popup calendar
no of values : unlimited.

field_date
type: Entity Reference
widget : Autocomplete
no of values : unlimited.

field_flag
type: boolean
widget : checkbox/radiobutton
no of values : unlimited.

I think the code for field_user should be as

$node->field_user[]['target_id'] =  $user->name;

but still i am getting error that is WSOD

share|improve this question
Have you tried : $node->field_user['und'][]['target_id'] – pico34 Aug 22 at 12:46
Can I assign user->name to target_id or should I assign it to $user->uid ? – user13198 Aug 22 at 12:48
target_id is for an uid reference – pico34 Aug 22 at 12:49
it works with $node->field_user['und'][]['target_id'] ..and now what about time field? – user13198 Aug 22 at 12:51
1  
For boolean the column name is 'value', for date the potential names are 'value', 'value2', and another one to do with the timezone (can't recall the name off the top of my head) – Clive Aug 22 at 13:12
show 5 more comments

1 Answer

up vote 3 down vote accepted

I think

$node->field_user['und'][]['target_id']

and

$node->field_time['und'][]['value']

is the good way

share|improve this answer
for field_time i getting error .. even after using $node->field_time['und'][]['value'] ?? – user13198 Aug 22 at 12:59
pls check the updated question I have also added boolean field... – user13198 Aug 22 at 13:01
enable devel module you'll be able to see the node object structure – pico34 Aug 22 at 13:05
is it present in the core> – user13198 Aug 22 at 13:06
1  
lol no, i can't do it for u – pico34 Aug 22 at 13:07
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.