1. create a cck field called "myfile" in a content type of your choice.
2. create a testing module called "mymodule".
<?php
/**
* Implementation of hook_menu()
*/
function mymodule_menu() {
$items = array();
$items['test'] = array(
'title' => 'test',
'page callback' => 'mymodule_test',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function mymodule_test() {
return drupal_get_form('mymodule_test_form');
}
function mymodule_test_form() {
module_load_include('inc', 'content', 'includes/content.node_form');
$form = array();
// Definition of the CCK fields array that we want to use in our custom form
$fields = array('field_myfile');
foreach ($fields as $name) {
// Calling the CCK API function to create the field
$field = content_fields($name);
// Put element information into hidden non-displaying form container
$form['#field_info'][$name] = $field;
// Render the element, then add the rendered element to the form.
$form += (array) content_field_form($form, $form_state, $field);
}
// You can set weight for the paticular element
$form['field_myfile']['#weight'] = 1;
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Send',
'#weight' => 2,
);
return $form;
}
function mymodule_test_form_submit($form, &$form_state) {
echo '<pre>';
print_r($form_state);
echo '</pre>';
}
?>
No comments:
Post a Comment