Hi Guys,

I have extracted the code of form 'node/add/image' from the node module and image module to create a complete form. I have done it using this code......this function get two parameter first shows the type of the module...i.e; 'image' and the second shows the 'group ID' using OG module.

function test_form_image($cat_arr, $gid){
if(module_exists('image')){
global $user;
$gids[]=$gid;

$row_image_form = Array();
if($user->uid)
$row_image_form['uid'] = $user->uid;
else
$row_image_form['uid'] = '0';
$group_type = 'image';
$sql = "SELECT * from node_type where type='image'";
$result = db_query($sql);
$row_image_form = db_fetch_object($result);
// $form['#id'] = 'newsite_image';
// $form['#id'] = 'test_form_'.$cat_arr;
$form['#id'] = 'node_form';
$form['#attributes'] = array("enctype" => "multipart/form-data");
$form['newsite_image'] = array('#type' => 'fieldset',
'#title' => t('Add images to your album now?'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '

',
'#suffix' => '

',
);
$form['newsite_image']['gid'] = array('#type' => 'hidden',
'#title' => t(''),
'#value' => $gid,
);
$form['newsite_image'] = array_merge_recursive($form['newsite_image'], node_invoke($row_image_form->type, 'form', $gids));
$c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $group_type);
while ($vocabulary = db_fetch_object($c)) {
if ($vocabulary->tags) {
$typed_terms = array();
foreach ($terms as $term) {
// Extract terms belonging to the vocabulary in question.
if ($term->vid == $vocabulary->vid) {

// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($term->name, ',') !== FALSE || strpos($term->name, '"') !== FALSE) {
$term->name = '"'.str_replace('"', '""', $term->name).'"';
}

$typed_terms[] = $term->name;
}
}
$typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);

if ($vocabulary->help) {
$help = $vocabulary->help;
}
else {
$help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
}
$form['newsite_image']['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
'#title' => $vocabulary->name,
'#description' => $help,
'#required' => $vocabulary->required,
'#default_value' => $typed_string,
'#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
'#weight' => $vocabulary->weight,
'#maxlength' => 255,
);
}
else {
// Extract terms belonging to the vocabulary in question.
$default_terms = array();
foreach ($terms as $term) {
if ($term->vid == $vocabulary->vid) {
$default_terms[$term->tid] = $term;
}
}
$form['newsite_image']['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
$form['newsite_image']['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
$form['newsite_image']['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
}
}
if (is_array($form['newsite_image']['taxonomy']) && !empty($form['newsite_image']['taxonomy'])) {
if (count($form['newsite_image']['taxonomy']) > 1) { // Add fieldset only if form has more than 1 element.
$form['newsite_image']['taxonomy'] += array(
'#type' => 'fieldset',
'#title' => t('Categories'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
}
// $form['newsite_image']['taxonomy']['#weight'] = -3;
// I have commented to keep the category section down
$form['newsite_image']['taxonomy']['#tree'] = TRUE;
}
///////////////////////////////////////////////getting from og/////////////////////////////////
$required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
if (user_access('administer nodes')) {
$options = og_all_groups_options();
}
else {
$subs = og_get_subscriptions($user->uid); //changed
foreach ($subs as $key => $val) {
$options[$key] = $val['title'];
}
}
$vis = variable_get('og_visibility', 0);
if (user_access('administer organic groups') && $vis < 2) {
$vis = $vis == OG_VISIBLE_GROUPONLY ? OG_VISIBLE_CHOOSE_PRIVATE : OG_VISIBLE_CHOOSE_PUBLIC;
}
elseif (!count($options)) {
// don't show checkbox if no subscriptions. must be public.
$vis = OG_VISIBLE_BOTH;
}
switch ($vis) {
case OG_VISIBLE_BOTH:
$form['newsite_image']['og_public'] = array('#type' => 'value', '#value' => 1);
break;
case OG_VISIBLE_GROUPONLY:
$form['newsite_image']['og_public'] = array('#type' => 'value', '#value' => 0);
break;

//user decides how public the post is.
case OG_VISIBLE_CHOOSE_PUBLIC:
$form['newsite_image']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 1, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always Public.'), '#weight' => 2);
break;
case OG_VISIBLE_CHOOSE_PRIVATE:
$form['newsite_image']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 0, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always Public.'), '#weight' => 2);
break;
}
$simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE) && count($gids);
if (count($options) == 1 && $required) {
$gids = array_keys($options);
$gid = $gids[0];
$groups = array($gid);
// also show read only mode if user has 1 option and we are in required mode
$simple = TRUE;
}
elseif ($gids) {
// populate field from the querystring if sent
$groups = $gids;
if (!user_access('administer nodes')) {
// filter out any groups where author is not a member. we cannot rely on fapi to do this when in simple mode.
$groups = array_intersect($gids, array_keys($options));
}
}
elseif ($node->nid || $node->og_groups) {
$groups = $node->og_groups;
}
else {
$groups = array();
}

if ($simple) {
// 'simple' mode. read only.
if (count($groups)) {
foreach ($groups as $gid) {
$titles[] = $options[$gid];
$item_value = implode(', ', $titles);
}
$form['newsite_image']['visible']['og_groups_visible'] = array('#type' => 'item', '#title' => t('Audience'), '#value' => $item_value);
$assoc_groups = drupal_map_assoc($groups);
// this hidden element persists audience values during a Preview cycle. avoids errors on Preview.
$form['newsite_image']['invisible']['og_groups_hidden'] = array('#type' => 'hidden', '#value' => serialize($assoc_groups));
// this 'value' element persists the audience value during submit process
$form['newsite_image']['invisible']['og_groups'] = array('#type' => 'value', '#value' => $assoc_groups);
}
}
elseif ($cnt = count($options)) {
drupal_add_js(drupal_get_path('module', 'og'). '/og.js');
// show multi-select. if less than 20 choices, use checkboxes.
$type = $cnt >= 20 ? 'select' : 'checkboxes';
$form['newsite_image']['visible']['og_groups'] = array(
'#type' => $type,
'#title' => t('Audience'),
'#attributes' => array('class' => 'og-audience'),
'#options' => $options,
'#required' => $required,
'#description' => format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.'),
'#default_value' => $gids,
'#required' => $required,
'#multiple' => TRUE);
}
else if ($required) {
form_set_error('title', t('You must !join before posting a %type.', array('!join' => l(t('join a group'), 'og'), '%type' => node_get_types('name', $node->type))));
}

if (count($form['newsite_image']['visible']) > 1) {
$form['newsite_image']['#type'] = 'fieldset';
$form['newsite_image']['#title'] = t('Groups');
$form['newsite_image']['#collapsible'] = TRUE;
$form['newsite_image']['#collapsed'] = $gids ? TRUE : FALSE;
}
if (module_exists('og_author')){
$form['newsite_image']['author']['og_author'] = array('#type' => 'select',
'#title' => t('Author group'),
'#options' => $options,
'#required' => $required,
'#description' => t('Select the group that will be authoring this post.'),
'#required' => $required,
'#multiple' => FALSE);
$form['newsite_image']['author']['#type'] = 'fieldset';
$form['newsite_image']['author']['#title'] = t('Author group');
$form['newsite_image']['author']['#collapsible'] = TRUE;
$form['newsite_image']['author']['#weight'] = 1;
} // end of if for module_exists('og_author')
//////////////////////////////////////////////end /////////////////////////////////////////////
//////////////////////////////////////////////start from class_image.inc /////////////////////////////////////////////
$vid = acidfree_get_vocab_id();
if (($arg = _path_match('node', 'add', 'image', '%d'))) {
$album = acidfree_get_node_by_id($arg[0]);
$form['newsite_image']['taxonomy'][$vid]['#default_value'] = array($album->tid);
}
_acidfree_filter_taxonomy($form['newsite_image']['taxonomy'][$vid]);
$js_attrs = array('onchange' => 'set_title(this.value);');
$form['newsite_image']['image']['#attributes'] = is_array($form['image']['#attributes']) ?
array_merge($js_attrs, $form['newsite_image']['image']['#attributes']) : $js_attrs;
$form['newsite_image']['body']['#rows'] = 5;
$rotate_options = Array(
'270' => t('Counterclockwise'),
'0' => t('No rotation'),
'90' => t('Clockwise'),
'auto'=>t('Use exif orientation tag'),
);
$form['newsite_image']['rotate'] = array(
'#type' => 'select',
'#title' => t('Rotate image'),
'#default_value' => '0',
'#options' => $rotate_options,
'#acidfree_form' => true,
'#attributes' => array('class' => 'rotate'),
);
if (($arg = _path_match('album', '%d', 'contents'))) {
unset($form['newsite_image']['image']);
unset($form['newsite_image']['format']);
}

//////////////////////////////////////////////end from class_image.inc////////////////////////////////////////////////
$form['newsite_image']['Submit'] = array(
'#type' => 'submit',
'#value' => 'Submit image',
'#weight' => 45,
);
return $form;
}else{
drupal_set_message('Image module does not exist');
}
} // end of function test_form_image

This code developes the form accurately.
For submission of this form I am using this code...........

function test_form_image_submit($form_id, $form_values){
drupal_set_message(t('I love my country.........'));
global $user;
if($user->uid)
{
$form_values['uid'] = $user->uid;
$form_values['name'] = $user->name;
$form_values['type'] = 'image';
$form_values['grant_view'] = '1';
$form_values['comment'] = '2';
//$node = (object)$node;
node_object_prepare($node);
if (!isset($form_values['created'])) {
$form_values['created'] = time();
}
if (!isset($form_vlaues['date'])) {
$form_values['date'] = format_date($form_values['created'], 'custom', 'Y-m-d H:i:s O');
}
//node_invoke($node, 'prepare');
//node_invoke_nodeapi($node, 'prepare');
$node_options = variable_get('node_options_'. $form_values['type'], array('status', 'promote'));
if (!isset($form_values['nid'])) {
foreach (array('status', 'promote', 'sticky', 'revision') as $key) {
$form_values[$key] = in_array($key, $node_options);
}
$form_values['uid'] = $user->uid;
}
else {
// Nodes being edited should always be preset with the default revision setting.
$form_values['revision'] = in_array('revision', $node_options);
}
if (og_is_group_type($form_values['type'])) {
$form_values['comment'] = COMMENT_NODE_DISABLED;
}

// Reset to follow site default theme if user selects the site default
if ($form_values['og_theme'] == variable_get('theme_default', 'bluemarine')) {
$form_values['og_theme'] = NULL;
}

// start of node_form_submit//
$node = node_submit($form_values);
// Prepare the node's body:

if ($node->nid) {
node_save($node);
watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node))));
}
else {
// node_load($node->nid);
// node_prepare($node->nid);
node_save($node);
watchdog('content', t('@type: added %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node))));
}

// end//
//if op=insert//
if (og_is_group_type($node->type)) {
newsite_insert_group($node);
// make sure the node owner is a full powered subscriber
og_save_subscription($node->nid, $node->uid, array('is_active' => 1, 'is_admin' => 1));

$account = user_load(array('uid' => $node->uid));
$variables = array(
'@group' => $node->title,
'!group_url' => url("node/$node->nid", NULL, NULL, TRUE),
'@username' => $account->name,
'!invite_url' => url("og/invite/$node->nid", NULL, NULL, TRUE)
);

// alert the user that they are now the admin of the group
$from = variable_get('site_mail', ini_get('sendmail_from'));
drupal_mail('og_new_admin', $account->mail, _og_user_mail_text('og_new_admin_subject', $variables), _og_user_mail_text('og_new_admin_body', $variables), $from);
}
elseif (!og_is_omitted_type($node->type)) {
og_save_ancestry($node);
}

// TODO: move this to cron to help give time to fix typos, and help scaling. create new module
// implementing an SMTP library that uses cron.
if (!module_exists('og2list')) {
if ($node->status && og_node_type_notify($node->type)) {
$node->msgid = "$node->nid-0". og_msgid_server();
og_mail(node_get_types('name', $node), $node);
}
}
////////////////////start of block///////////////////////////
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $node->nid, time());
if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
// Log this page access.
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), $_SERVER['REMOTE_ADDR'], $user->uid, session_id(), timer_read('page'), time());
@db_query('INSERT INTO {history} (uid, nid, timestamp) VALUES (%d, %d, %d)', $user->uid, $node->nid, time());
}
////////////////////////////////////////////////////////////////////////////end of block //////////////////////////////////
} // end of if for user->uid
}// end of function test_form_image_submit

This submission method adds all node information of this image in the database but doesn't add values in the files table in the database and also doesn't upload the image.
After submission of this form 'your image has been created' message is displayed with a red line like this...
*The selected file E:\work\31mayclientdrupal5_newsite\files could not be copied.*

How I can solve this issue................Thanks in advance.
CRINCH