Trying to set a default value on an entity reference field.
$unitid = node_load($unit); $form['field_choose_a_service']['und']['#default_value'] = $unitid;
Warning: Illegal offset type in form_type_checkboxes_value() (line 2390 of /homepages/43/d503288075/htdocs/example.co.uk/includes/form.inc).
Notice: Object of class stdClass could not be converted to int in form_process_checkboxes() (line 3316 of /homepages/43/d503288075/htdocs/example.co.uk/includes/form.inc).
And targeting the nid from that loaded node...
$unitid = node_load($unit); $form['field_choose_a_service']['und']['#default_value'] = $unitid->nid;
Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value() (line 2389 of /homepages/43/d503288075/htdocs/example.co.uk/includes/form.inc).
The first one actually works, but kicks up the errors. What am I doing wrong?
Essentially I want to check if the nid im passing in the URL as a _GET query matches an option in the entity reference checkbox options, and make that option selected if it does.