Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Hi everyone ,
I wrote a module to create a basic form. So i create the folder formexample in drupal-6.2/sites/all/modules/ , and i put in the folder (formexample) the following files:
formexample.info:
------------------------------------------------------------------------
;$Id$
name = Form example
description = Shows how to build a basic form
core = 6.x
------------------------------------------------------------------------
formexample.module:
-----------------------------------------------------------------------------------------------
<?php
//$Id
/*
* Implementation of hook_menu().
*/
function formexample_menu(){
$items = array();
$items[] = array(
'path'=>'formexample',
'title'=>t('View the form'),
'page callback'=>'formexample_page',
);
}
/*
* Called when user goes to http://localhost/drupal-6.2/formexample
*/
function formexample_page(){
return drupal_get_form('formexample_nameform');
}
/*
* Defines a form
*/
function formexample_nameform($form_state){
$form['user_name']=array(
'#title'=>t('Your name'),
'#type'=>'textfield',
'#description'=>t('Please enter your name.')
);
$form['submit']=array(
'#type'=>'submit',
'#value'=>t('Submit')
);
return($form);
}
/*
* Validate the form
*/
function formexample_nameform_validate($form, &$form_state){
if ($form_state['values']['user_name'] == 'King Kong') {
form_set_error('user_name',t('King Kong is not allowed to use this form.'));
}
}
/*
* Handle post-validation form submission
*/
function formexample_nameform_submit($form, &$form_state){
$name = $form_state['values']['user_name'] ;
drupal_set_message(t('Your form has been saved.'));
//drupal_set_message(t('thanks for filling out the form,%name',array('%name'=>$name)));
}
-----------------------------------------------------------------------------------------------
Then i go to admin/build/modules and i enable the module and everything went OK. But when i go to http://localhost/drupal-6.2/formexample i got the following message in my browser :
"Page not found
The requested page could not be found. "
Why drupal can not find this page? Is this a problem in my hook_menu function? What should i do? I have tried to create a form in drupal 6.2 since a couple of weeks. Can anybody help me?
thanks in advance!!!!
[Edited to add <code> and </code> tags; nevets]
Comments
your hook_menu
I recommend reading http://drupal.org/node/102338 - the path is the array index not a separate key as it was in D5. Also it seems you forgot returning $items.
--
The news is Now Public | Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile. |
--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.