Forms without a menu entry
Thu, 2011-11-10 08:51
I want to create a form that I can fill in simply by typing www.example.com/sample-form. All the examples seem to attach all forms to menu items. Is it possible to have a form that is not in a menu?
Cheers,
Martin.
Thu, 2011-11-10 14:58
#2
Thank you
Thank you very much. Solved!
Whenever you implement hook_menu(), you can achieve this by setting the "type" parameter to MENU_CALLBACK. That way the link will be accessible but won't appear as a link. Like this...
$items[sample-form] = array(
'title' => 'Sample Form',
'page callback' => 'drupal_get_form',
'page arguments' => array('sample_form'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function sample_form($form, &$form_submit) {
//The way you implement the form is up to you...
}
If you take a look a the this video http://buildamodule.com/video/drupal-7-development-core-concepts-how-to-......
Notice that if you don't specify the "type" parameter it will default to MENU_NORMAL_ITEM which will create a navigation link. So the key is setting to MENU_CALLBACK...