Hey Guys ... I figured it out how to do that!
(but still only one problem)
Using Firebug (Mozilla Firefox plugin), i managed to figure out the name of the elements and then fill it with the proper values.
Creating a 'page' node programmatically, in Drupal 7, is done using the following code:

<?php
global $user;
$customNode = new stdClass();
$customNode->type = 'page';
node_object_prepare($customNode);
$customNode->uid = $user->uid;
$customNode->name = $user->name;
$customNode->title = 'Your page title';
$customNode->language = 'en';
$customNode->body[$customNode->language][0]['value'] = 'Your value';
$customNode->body[$customNode->language][0]['summary'] = 'Your summary';
$customNode->body[$customNode->language][0]['format'] = 'filtered_html';
$customNode->menu['enabled'] = 1;       // 1 to enable providing a link in main menu
$customNode->menu['link_title'] = 'Your page link title';
$customNode->menu['description'] = 'Your page description';
$customNode->menu['parent'] = 'main-menu:0';
$customNode->menu['weight'] = 5;
$customNode->path['alias'] = 'Your Alias';
$customNode->comment = 1;
$customNode->status = 1;        // 1 means published
$customNode->promote = 0;
$customNode->revision = 0;
$customNode->changed = $_SERVER['REQUEST_TIME'];
$customNode->created = $_SERVER['REQUEST_TIME'];
node_submit($customNode);
node_save($customNode);
?>

But this not completely functioning :( .
The page is being created successfully with all the values, but the link is not shown in main menu navigation (i mean in the main menu tabs near the Home tab).
I checked it out in the created content and it's there, accessed it via "edit" button, pressed "save" (without editing anything), and it appears in the main menu!!!

I want it to show automatically when created.

Any ideas?!

Comments

You could just use drupal_goto:

<?php
drupal_goto
('node/' . $customNode->nid);
?>

That's not what i wanted!

In the above code i'm creating a page node and creating a menu link for it to be shown as a main menu tab. Everything is done just fine except for the displaying of the link tab!

When my programmatic page is created, the link tab in the main menu is not shown until i manually enter the edit form of this page and just press save at the end of this form!

My aim is to make everything completely programmatic.

So ... how can that be done?

Sorry, got the wrong end of the stick. Try something like this:

<?php
$customNode
->menu = array(
   
'enabled' => 1,
   
'mlid' => 0,
   
'module' => 'menu',
   
'hidden' => 0,
   
'has_children' => 0,
   
'customized' => 0,
   
'options' => array(),
   
'expanded' => 0,
   
'parent_depth_limit' => 8,
   
'link_title' => 'Title',
   
'description' => '',
   
'parent' => 'main-menu:0',
   
'weight' => 0,
   
'plid' => 0,
   
'menu_name' => 'main-menu'
);
?>

You'll need to tweak a few of the values but I'm guessing there's at least one of those that isn't provided in your current code that the menu module needs to properly attach the link to the menu. That's why when you go to the menu page and save it it works, because the admin page adds defaults/hidden values.

Thank you man! You really nailed it!
Your a life saver.

The code worked like a charm.

Thanks again.

Best Regards.

im a beginner to this.please tell me where i save this file in my drupal directory?

Madura, this would typically be a bit of code used in a modules' .module file. You would call this bit of code when desired to create a node outside of doing it in the user interface. I'd suggest http://buildamodule.com if you're looking into learning how to do Drupal programming. It's helped me.