English 中文(简体)
• 如何为Droupal的行政使用者制定习俗表格?
原标题:How to develop custom forms for Drupal s admin users?
  • 时间:2010-11-14 18:54:33
  •  标签:
  • drupal
  • forms

为系统管理部分制定破产习惯表格的最佳途径是什么?

事先感谢你!

最佳回答

First thing, you need a location to access your form from, preferably in the "admin/*" namespace if the form is only meant for administration. If you re just showing a form, you could directly use drupal_get_form as page callback (but you could use any function to generate the HTML code, even mix with theme functions)

Also, you need to know which permission(s) is required to access the form. By default, I used "access administration pages" but you probably should use something more specific, depending on what you intend the form for.

请允许我说,“admin/build/aboutthing”,你需要使用。 登记这条道路:

/**
 * Implementation of hook_menu().
 */
function modulename_menu(){
    return array(
         admin/build/something  => array(
             title  =>  Example Admin Form ,
             description  =>  Admin form introduced by the MODULENAME module ,
             type  => MENU_NORMAL_ITEM,
             page callback  =>  drupal_get_form ,
             access arguments  => array( access administration pages ),
        ),
    );
}

Now, to actually display a page: the value provided in "page arguments" was the name of the function that drupal_get_form expects to provide the form structure (which must be an associative array):

/**
 * Form Structure
 */
function modulename_form_something(&$form_state){
    $form = array();
    $form[ myfield ] = array(
         #title  =>  My Field ,
         #description  =>  This is a basic text input field ,
         #type  =>  textfield ,
         #default_value  => $form_state[ values ][ myfield ],
    );
    //
    // Here you can add more elements in the form
    //
    return $form;
}

http://api.drupal.org/api/drupal/developer---topics-forms_api_ Reference.html/6“rel=“noreferer” 提供更多关于表格的信息,你可以用来方便地制作某些极为复杂的表格。


现在,你的形式在“行政/管理/建造/铺设”上显示,但你可能希望与这些数据相呼应;否则,鉴定和提交职能的名称与形式结构功能相同,其名称分别为“<>_validate和“_submit(无论你如何用#validate#submit,以结构的形式。

例如,说“no”不是有效价值,其他一切都被接受。

/**
 * Form validation
 */
function modulename_form_something_validate($form, &$form_state){
    if ($form_state[ values ][ myfield ] ==  no ){
        form_set_error( myfield ,  "<b>no</b>" is not a valid answer, try again. );
    }
}

鉴定首先叫作验证,但是,只有在数据正确无误的情况下,才能检查。 如果在收到表格时需要采取行动,则在“提交书”的手稿中这样做,是因为在提交表格时,可以多次确认。

/**
 * Form submission
 */
function modulename_form_something_submit(&$form, &$form_state){
    //
    // Here you can perform whatever action that form is made for.
    //
    drupal_set_message(  The form has been sent. "myfield" has the following value:  .$form_state[ values ][ myfield ] );
}

请总结一下,全文见<代码>。

<?php

/**
 * Implementation of hook_menu().
 */
function modulename_menu(){
    return array(
         admin/build/something  => array(
             title  =>  Example Admin Form ,
             description  =>  Admin form introduced by the MODULENAME module ,
             type  => MENU_NORMAL_ITEM,
             page callback  =>  drupal_get_form ,
             page arguments  =>  modulename_form_something ,
             access arguments  => array( access administration pages ),
        ),
    );
}

/**
 * Form Structure
 */
function modulename_form_something(&$form_state){
    $form = array();
    $form[ myfield ] = array(
         #title  =>  My Field ,
         #description  =>  This is a basic text input field ,
         #type  =>  textfield ,
         #default_value  => $form_state[ values ][ myfield ],
    );
    //
    // Here you can add more elements in the form
    //
    return $form;
}


/**
 * Form validation
 */
function modulename_form_something_validate($form, &$form_state){
    if ($form_state[ values ][ myfield ] ==  no ){
        form_set_error( myfield ,  "<b>no</b>" is not a valid answer, try again. );
    }
}


/**
 * Form submission
 */
function modulename_form_something_submit(&$form, &$form_state){
    //
    // Here you can perform whatever action that form is made for.
    //
    drupal_set_message(  The form has been sent. "myfield" has the following value:  .$form_state[ values ][ myfield ] );
}

Don tabes女士还需要一份.info文档,以便安装模块:

资料来源:<代码>。

; $Id
name = Admin Form
description = This module adds an admin form
package = Example Module
core = "6.x"
version = "6.x-0.1-dev"
问题回答

Dr子系统将有助于你采取你所需要的任何形式。 如果您需要储存环境,system_dings_form 只是一小.。

制作行政表格时的唯一区别是,要记住确定某种必要的许可,并在网站<代码>/admin/部分放置某些地方。 确实,没有什么东西专门涉及行政形式。

除非我误解你的问题,否则,我认为你可以通过使用网络格式模块,避免表格张。

没有任何法律要求,没有科学分析,也没有统计工具。

http://drupal.org/project/webform

看到两部辅导录像,你不时只是就任何形式进行拍照。





相关问题
C# Form Problem: new form losing control and randomly hiding

I m encountering strange behavior with forms on a c# 3.5 app. On a button click, my form1 hides itself, creates a new form2, and shows form2. Form1 also contains the event method triggered when ...

TCPlistener.BeginAcceptSocket - async question

Some time ago I have payed to a programmer for doing multithread server. In the meantime I have learned C# a bit and now I think I can see the slowndown problem - I was told by that guy that nothing ...

RoR: before_save on nested object in form?

I have a form with a nested object (customer < order), and it works except that it keeps creating a new customer record. I d like to have it check to see if an existing customer is already ...

Receive POST from External Form

I have a form on another website (using a different backend) that I want to be able to POST to my Rails application (on a different domain). How do I generate a valid authenticity token for the ...

Getting posted values in MVC PartialView

I ve created a PartialView which I render with Html.RenderPartial, passing the name of the view and the strongly-typed data item to bind to (below): <% Html.RenderPartial("...

Recaptcha - Form Customization

Does anyone know if recaptcha can be fully customize without the default frame. I need the recaptcha image to only be a certain width as well as the input field. Has anyone done this before with ...

Better way to retain form data on manual back redirect?

I have a form that, on submit, requires the customer to look over the data, and then confirm the changes before saving the data. However, I m using a really rough way of retaining data if the user ...

热门标签