Domanda

Sono nuovo di Drupal. Ho creato un modulo contace1 con il seguente codice:

contace1.info

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

contact1.module

// $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 questo codice che ho cercato di creare nuove forme di contatto

, ma non mostra alcun legame e sulla pagina di apertura direttamente dare pagina non trovata.

Nessuna soluzione corretta

Altri suggerimenti

Prima di tutto, MENU_CALL_BACK non definito in Drupal. Quello che si voleva scrivere è MENU_CALLBACK, che registra una voce di menu nel router menu. Questa voce non apparirà in qualsiasi menu visibile normalmente. Pensate a come una voce di menu nascosto. Se si vuole rendere visibile, l'uso MENU_NORMAL_ITEM.

'tipo' = MENU_CALL_BACK - menu è richiamata, si dovrebbe impostare a MENU_NORMAL_ITEM o manualmente creare menu nella pagina di amministrazione alla pagina contact1. di aggiornamento della cache.
ti raccomando pienamente leggere "Pro Drupal Development" da Vandyk, c'è esempi come creare forme:)

Il primo errore nel codice è che, se il modulo è denominato contact1.module, allora ogni gancio Implementa dovrebbe avere un nome che inizia con contact1_. Si dovrebbe quindi evitare di utilizzare contact_ in nome delle funzioni del modulo, in quanto v'è già il modulo di contatto in Drupal 6; nel caso in cui il modulo è per Drupal 6, ci sarebbe stato un conflitto tra i moduli.

Il secondo errore è che la costante che si sta utilizzando è MENU_CALLBACK, non MENU_CALL_BACK.

Se contact1.module poi è il nome del modulo, il file di informazioni che viene con esso deve essere denominato contact1.info, non contace1.info. Se si utilizza un nome sbagliato per quel file, Drupal 6 e superiore non dovrebbe mostrare il modulo nella lista dei moduli è possibile installare.

Ciao tenta di utilizzare questo codice

/**
* menu callback
*
*/

function contact_page()
    {
        $output = array(
            'item 1' => array(
              "#type" => 'markup',
              '#markup' =>  t('You can leave a message using the contact form below.'),
            ),
            'item 2' => array(
              "#type" => 'markup',
              '#markup' =>  drupal_get_form('contact_nameform'),
            ),
        );
        return $output;
    }
    /**
    * define the form
    */
function contact_nameform($form, $form_state)
    {  ..........
       .......

Qui, ho impostato markup tipo di uscita ritorno con contenuto e forma, impostare anche il parametro di contact_nameform ($ form, $ form_state)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top