Frage

Ich bin neu in Drupal. Ich habe einen contace1 Modul mit dem folgenden Code erstellt:

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 Code i versucht hat, neues Kontakt-Formular erstellen

, aber es zeigt keine Verbindung und beim Öffnen Seite direkt gibt Seite nicht gefunden.

Keine korrekte Lösung

Andere Tipps

Zunächst einmal ist MENU_CALL_BACK nicht in Drupal definiert. Was Sie schreiben wollte ist MENU_CALLBACK, die einen Menüpunkt im Menü-Router registriert. Dieser Artikel wird normalerweise nicht in sichtbarem Menü erscheinen. Betrachten Sie es als ein versteckten Menüpunkt. Wenn Sie möchten, um sie sichtbar zu machen, verwenden MENU_NORMAL_ITEM.

‚type‘ = MENU_CALL_BACK - Menü Rückruf ist, können Sie es zu MENU_NORMAL_ITEM setzen sollen oder manuell Menü im Admin-Seite contact1 Seite erstellen. Refresh-Cache.
empfehle ich Ihnen vollständig lesen „Pro Drupal Development“ von Vandyk, gibt es Beispiele dafür, wie Formulare zu erstellen:)

Der erste Fehler im Code ist, dass, wenn das Modul contact1.module genannt wird, dann wird jeder Haken es implementiert einen Namen beginnend mit contact1_ haben sollte. Sie sollten dann mit Kontakt_ im Namen Ihrer Moduls Funktionen vermeiden, da es bereits das Kontaktmodul in Drupal 6 ist; in dem Fall für Drupal Ihr Modul 6 ist, würde es einen Konflikt zwischen den Modulen sein.

Der zweite Fehler ist, dass die Konstante, die Sie verwenden, ist MENU_CALLBACK, nicht MENU_CALL_BACK.

Wenn dann contact1.module ist der Name des Moduls, die Info-Datei, die mit ihm kommt contact1.info benannt werden sollte, nicht contace1.info. Wenn Sie einen falschen Namen für die Datei verwenden, 6 Drupal und höher sollten zeigen, nicht das Modul in der Liste der Module können Sie installieren.

Hallo versuchen, diesen Code zu verwenden,

/**
* 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)
    {  ..........
       .......

Hier habe ich gesetzt Markup Typ Rückkehrausgang mit Inhalt und Form, setzt auch die Parameter von contact_nameform ($ form, $ form_state)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top