By newbstah on
Hi There -
Am having a heck of a time with this. This is the first time I've made a module with the menu system or a form. I'm able to get the title to show up on the page but nothing else. It's supposed to be a form with a single text field and a submit button. The reason it has to be something simple is that there just isn't that much here to mess up. The module is enabled.
I've searched for everything I can think of but there's nothing I can find that has helped. I'm hoping that it's something glaringly obvious to someone experienced with these things. Please have a look. I'm leaving some of the things I've tried in place, but commented out.
<?php
/**
* Implementation of hook_menu
*/
function example_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/example',
'title' => t('Example Form'),
//'callback' => 'example_page',
'callback' => 'drupal_get_form',
'callback arguments' => array('example_form'),
//'type' => MENU_CALLBACK,
'access' => 'does stuff with one field',
//'pid' => 390,
);
}
return $items;
}
/**
* Implementation of hook_form()
*/
function example_form() {
//$form['example']['add_nid'] = array(
$form['add_nid'] = array(
'#type' => 'textfield',
'#title' => t('put nid here'),
'#size' => 30,
'#rows' => 1,
'#description' => t('Enter nid.'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('submit'),
);
}
function example_form_validate($form_id, $form_values) {
// Do stuff with $form_values here and set errors if needed.
}
function example_form_submit($form_id, $form_values) {
// has been tested on a php-page and works.
return drupal_set_message('Thank you for submitting the form!');
}
/*
function example_page() {
return drupal_get_form('example_form');
}
*/
?>
Comments
You should add function
You should add
add return $form at the bottom of ***_form ;
====================
http://aymoo.cn
Have you tried
Have you tried disabling/re-enabling your module?
That rebuilds the paths which might be you're problem.
-- edited to say -
whoops didn't read the whole post - ignore me!
Angels are singing!
Thank you both for replying. Adding the return did it! Thanks!
where it is display
I use the above code,
But i am not find where it is displaying...