Hi All,
I'm trying to create a new type of nodereference field by which you can build a list of referenced nodes trough one suggest field. The referenced nodes are added via js to a table for nice viewing and to a hidden field to pass (the nids of) all referenced nodes after submitting. See the screenshot for a better understanding: http://www.wieni.be/noderefer_screen.jpg
All of this works fine, except the saving of the referenced nodes to the database. The values in my hidden field are not passed on. When I do a check in the action 'process form values' the parameter $items['nids'] is empty. Here are some parts of my code:
function noderefer_widget($op, &$node, $field, &$items) {
if ($field['widget']['type']=="noderefer_select") {
switch ($op) {
//... i took away some code here
case 'form':
//... i took away some code here
$form[$field['field_name']] = array('#tree' => TRUE);
$form[$field['field_name']]['nids'] = array(
'#type' => 'textfield',
'#weight' => 10,
'#default_value' => $items['default nids'],
'#attributes' => array('class' => ($field['field_name'] ."-nids")),
);
return $form;
break;
case 'process form values':
drupal_set_message(var_export($items,true)); // <-- $items['nids'] is not there
//... i took away some code here
So, if you're still following, the problem is that in alle examples I saw and also in the nodereference module itself, $items['nids'] just contains the values you filled in in the submit form. Except in my case, $items['nids'] does not exist or get striped along the way.
I realise using a hidden field to pass on nids might not be the.. cleaniest way to go so any suggestions on that matter are also greatly appreciated... thx!
Further reading about the _widget hook: http://www.drupalogy.com/api/function/hook_widget
Comments
subscribe
subscribe
Drupal samurai for hire, based in Buffalo, New York, USA.
15+ years Drupal, 20+ years web.
http://basicmagic.net
Solved
The matter solved itself by changing the type of the form field from 'hidden' (or 'textfield') to 'select'.
Browsing through the nodereference module I discovered that it only accepts referenced input from autocomplete or select fields, but no others. Using a text/hidden field was bound not to work. Ofcourse that will be documented somewhere, I just discovered it a bit late :)
I solved my problem quite dirty by changing my field to the 'select'-type and put it out of sight with the use of some css (display:none)