I've written a module that grabs data from an XML doc and creates a node out of it. In my node type I have checkboxes. I have made the relevant information appear in one of the xml fields as a comma-separated list, which i explode and then populate the checkboxes appropriately. This is where I'm stuck. I see the checkboxes take the form field_thisfield[keys][element], with value 'element' on the standard submit-node form. How do I deal with this programmatically? How can I check the appropriate boxes while creating the node through my module?

Comments

Anonymous’s picture

Oh I have the answer for that Bruce, its like this:

$node = new StdClass();


$input = 'element1,element2,element3';
// this could be from your XML or whatever as long as it was in this form and the elements matched
// the options in the standard non-programmatic form, the below would work
$list = explode(',',$input);
foreach ($list as $i){
    // this is the bit you're interested in the rest you already know
    $checkit[]['value'] = $i;
}
$node->field_thisfield = $checkit;

// rest of the things you need in the node

node_save($node);

Bruce.

Anonymous’s picture

Thanks Bruce

robloach’s picture

Status: Active » Fixed

You're a helpful man, Bruce.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.