Hello.
I want to implement an easy module, to make a custom cck field.
I just want a textfield and an uploadfield being put together, so if the user hits "add another item" another row with these two fields appear.
The upload field should not be required.
I´ve seen some tutorials for example the one about the compound field: http://www.poplarware.com/cckfieldmodule.html
But this depends on the filefield module and you dont have the choice not to upload a file.
So i just took this easy module form lullabot : http://www.lullabot.com/articles/creating-custom-cck-fields
and achieved to let two textfields appear in the form.
But i really dont know how to achieve, that the second field becomes an upload field that works.
I dont care about validation now, i just want a hint what to do.
This is from my module, where the for is generated.
If i try to upload something, of course - nothing happens...
function example_widget(&$form, &$form_state, $field, $items, $delta = 0) {
$element['#attributes']['enctype'] = 'multipart/form-data';
$element['value'] = array(
'#title' =>'soso'.$delta,
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#autocomplete_path' => $element['#autocomplete_path'],
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
'#attributes' => array('class' => 'example'),
'#maxlength' => !empty($field['max_length']) ? $field['max_length'] : NULL,
);
$element['new']['upload'] = array(
'#name' => 'files['. $element['#field_name'] .'_'. $element['#delta'] .']',
'#type' => 'file',
'#description' => "argh",
'#size' => 22,
);
$element['new']['attach'] = array(
'#type' => 'submit',
'#value' => t('Attach'),
'#name' => 'attach',
'#ahah' => array(
'path' => 'upload/js',
'wrapper' => 'field_example_values',
'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
),
'#submit' => array('node_form_submit_build_node'),
);
return $element;
}
Has anybody a hint or link what steps are required to make this basic upload module work ?
Best,
Felix