I am able to programmatically create and populate nodes by using techniques such as this :


$nodeAr['field_name'][0] = array('value' => $aValue);
// ... etc ... //

$node = (Object)$nodeAr;
// ... //

node_save($node);

But I can't seem to get this to work for radio buttons. How would I set up the array for the field so that it converts to an object value that Drupal and CCK recognize when saving the node?

Comments

jmlavarenne’s picture

Title: Progarmmatically populating radio button field » Programmatically populating radio button field
Antinoo’s picture

Title: Programmatically populating radio button field » Populating radio button fields using PHP

Subscribing.
I think it would be very very useful for other modules a cck_* function which could handle this kind of task.

Not only for radio buttons, but for every CCK type.

You can see an imaginary example in this forum topic I opened yesterday.
Maybe something like that already exists, or there's some code which could be reused. I'm sorry, but I don't know.

Let me know what do you think about.

Greetings, Giovanni

jmlavarenne’s picture

The above technique also fails with select fields.

The only solution I've come up with which works is to save the value into the table field after the node has been created (by first retrieving the node->id) with an SQL command.

gcassie’s picture

Try manually creating a node of the type that has radio buttons, and put in some values. Then use the devel module to view how the data is structured with a dev load. If you mirror that structure, it should work.

Hope I understood your question properly.

karens’s picture

Status: Active » Closed (won't fix)

Closing old issues. None of us is using the D5 version any more, so hard to provide any support. Sorry.