tags:

views:

17

answers:

2

hi every one! I am new to drupal. I have created module with name contace1 code is below:-

contace1.info

; $Id$
name = Contact1
description = Show how to build contact form
package = Pro Drupal Development
core = 6.x

and contact1.module

<?php 
// $Id$

/**
* @file
* practice to build form
*/

/**
* Implimentation of hook_menue().
*/

function contact_menu()
    {
        $items['contact1'] = array(
            'title' => 'Contact',
            'page callback' => 'contact_page',
            'access argument' => array('access content'),       
            'type'=>MENU_CALL_BACK,
            'access callback' => TRUE,

            );
            return $items;

    }

/**
* menu callback
* called when user goes to http://localhost/drupaldemo/?q=contact
*/

function contact_page()
    {
        $output = t('You can leave a message using the contact form below.');
        //Return the html generated from $form data structure.
        $output.= drupal_get_form('contact_nameform');
        return $output;
    }
    /**
    * define the form
    */
function contact_nameform()
    {
        $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 contact_nameform_validate()
    {
        if($form_state['values']['user_name']=="")
            {
            form_set_error('user_name',t('Please enter your name.'));
            }

    }

/**
* handle post validation form submition
*/
function contact_nameform_submit($form ,&$form_state)
    {
    $name=$form_state['values']['user_name'];
    drupal_set_message(t('Thanks for filling out the form, %name',array('%name'=>$name)));

    }

im this code i have tried to create new contact form

but it does not show any link and on opening page directly give page not found

+1  A: 

First of all, MENU_CALL_BACK does not defined in Drupal. What you wanted to write is MENU_CALLBACK, which registers a menu item in the menu router. This item won't appear in any visible menu normally. Think of it as a hidden menu item. If you want to make it visible, use MENU_NORMAL_ITEM.

Yorirou
no it is not working
rajanikant
flush the menu cache (on your admin panel, there is subpage called `Performance`; on the bottom of that page there is a `Clear all caches` button)
Yorirou
+2  A: 

'type' = MENU_CALL_BACK - menu is callback, you should set it to MENU_NORMAL_ITEM or manually create menu in admin page to contact1 page. Refresh cache.

I recommend to you fully read "Pro Drupal Development" from Vandyk, there's examples how to create forms :)

Nikit

related questions