Drupal form property

drupal Form Properties

2008-08-08 15:43

When building the function in your form to build a form definition, the array of keys is used to declare a form of information. The following section lists the commonly used keys. Some keys will be automatically added and built form.

Form properties

The following section of the property-specific form. In other words, you can set $ form ['# programmed'] = TRUE, but if you set $ form ['myfieldset'] ['mytextfield'] [# programmed '] = TRUE then the form will not know your builder want it to do anything.

# Parameters

This property is an array containing the pass drupal_get_form () of the original parameters. By drupal_retrieve_form () can be added to the property.

# Programmed

This is a Boolean property to indicate a form is a way to process such as through drupal_execute () to submit. If you set the property before the form processing # post, you can use drupal_prepare_form () to set the property.

# Build_id

The property is a string (using MD5 hash). In the multi-step form, # build_id used to identify a specific form instance. It as a hidden field on the form, through the use of drupal_prepare_form () to set the form elements, as follows:

$ Form ['form_build_id'] = array (

'# Type' => 'hidden',

'# Value' => $ form ['# build_id'],

'# Id' => $ form ['# build_id'],

'# Name' => 'form_build_id',


# Base

This is an optional string attribute which if Drupal decides to call validation, submission, and theme function to use. Will be $ form ['# base'] is set to the prefix you want to use Drupal. For example, if you will be $ form ['# base'] set to 'foo', and calls drupal_get_form ('bar'), in bar_validate () and bar_submit () does not exist in the case, Drupal will use foo_validate () and foo_submit () as the processor. This property is also used to map the theme function. See drupal_render_form () ( http://api.drupal.org/api/5/function/drupal_render_form ).

# Token

The string (using MD5 hash) is a unique token, each form comes with it, through the token to determine a form Drupal is a true form and not a Drupal malicious user to modify after.

# Id

This property is a form_clean_id ($ form_id) the resulting string, and it is a HTML ID attribute. $ Form_id flip the bracket in any of "][", underscore "_" or a space character''will be replaced in order to generate consistent with the CSS ID.

# Action

The string property is the form tag action attribute. By default, it is request_uri () return value.

# Method

The string attribute refers to the form presented in a way --- usually post. API is based on the post form was constructed, it will not be processed using the GET method to submit the form. See the HTML specification on the part of the distinction between GET and POST. If you need to use the GET method, you may need to use Drupal's menu API, rather than the form API.

# Redirect

This property can be a string or an array. If the strings, then it is in the form is submitted after the user wants to redirect the Drupal path. If it is set to an array, the array will be passed to drupal_goto (), of which the first element of the array should be the target path (which will allow the drupal_goto () to pass additional parameters.)

# Pre_render

This property is an array, which contains previously presented in the form function to call. Each contains the function to call $ form_id parameter and $ form. For example, setting # pre_render = array ('foo', 'bar') will lead to Drupal first call the function foo ($ form_id, $ form), and then call the bar ($ form_id, $ form). When you want to verify the completion of the form after the show before, the use of hooks to modify the form structure is very useful. If you want to modify the form validation before use hook_form_alter ().

Add to all elements and attributes

When the form builder build forms using the form definition, it needs to ensure that each form element should have some default settings. These default values in the includes / form.inc function _element_info () in the set, but can be hook_elements () in the definition of the form elements covered.

# Description

All form elements will add the string property, which defaults to NULL. The theme function through form elements to render it. For example, textfield description appears in the textfield below the input box, as shown in Figure 10-2.

# Required

All form elements will add the Boolean property, which defaults to FALSE. It is set to TRUE, if the form is submitted after the time the field is empty, Drupal built-in form validation will throw an error message. Also, if it is set to TRUE, then the form will set a CSS class element (see includes / form.inc in theme_form_element ())

# Tree

All form elements will add the Boolean property, which defaults to FALSE. If it is set to TRUE, the form is submitted after the $ form_values array will be nested (rather than flat.) This will affect your access to submit data format. (See this chapter "field set (Fieldsets)" section).

# Post

The $ _POST array property of the original data, a copy of the form builder it will be added to all form elements. Thus, in the # process and # after_build defined functions can be based on the contents of # post to make intelligent decisions.

# Parents

All form elements will be added to the array property, it defaults to an empty array. It is for internal use form builder to identify the parent tree form, form element node. For more information, see http://drupal.org/node/48643 .

# Attributes

All form elements will be added to the array property, it defaults to an empty array, but the theme function will gradually fill the array. Members of the array will be used as HTML attributes. For example, $ form ['# attributes'] = array ('enctype' => 'multipart / form-data').

Common form element attributes

This section explains the properties of all the form elements can be used.

# Type

This declares a string type of form element. For example, # type = 'textfield'. Declaration form must contain the root of # type = 'form'.

# Access

This Boolean property determines whether the form element visible to the user. If the form element has a child form elements, and if the parent form element # access property to FALSE, then the child form elements will not be displayed. For example, if a form element is a set of fields, and if it's # access to FALSE, then the field is set all the fields which are not shown.

# Process

This property is an associative array. Each item in the array, a function name as key, any parameter passed to the function as a value. When building the form element will call these functions, allowing form element in the building to add additional operations. For example, the definition of the checkboxes in the system.module type of form in the building during the call set includes / form.inc inside the function expand_checkboxes ():

$ Type ['checkboxes'] = array (

'# Input' => TRUE,

'# Process' => array ('expand_checkboxes' => array ()),

'# Tree' => TRUE);

See this chapter "to collect all the possible elements of the definition of the form" part of another example. # Process the array when all the functions are called, for each form element to add a # processed attribute.

# After_build

This property is an array. Stored in an array constructed in the form elements you've got to call the function immediately. The function to be called each have two parameters: $ form and $ form_values. For example, if $ form ['# after_build'] = array ('foo', 'bar'), then the Drupal form element in the building after completion, were called foo ($ form, $ form_values) and bar ($ form, $ form_values). Once these functions are called after, Drupal for each form element in the internal add a # after_build_done property.

# Theme

This optional attribute defines a string, when the Drupal theme function for the form elements to find the time to use it. For example, setting # theme = 'foo', will make Drupal calls theme_get_function ('foo', $ element), the function will be in accordance with the sequential search function themename _foo (), themeengine _foo (), and theme_foo (). See earlier in this chapter "for the form to find the theme function" section.

# Prefix

This property is a string rendered in the form elements will be added to the front of the form elements.

# Suffix

This property is a string rendered in the form elements will be added to the back of the form elements.

# Title

The string is the title form elements.

# Weight

The property can be an integer or a fraction. When rendering the form element, it will be sorted according to their weight. Small weight will be put in front of the elements, heavy elements will be placed below the page positions.

# Default_value

The type of the property according to the type of form element. For the input form elements, if the form has not been submitted, then it is the value used in the field. Do it in the form element # value confusion. # Value form element defines the value of an internal form, the user can not see the value, but it is defined in the form and appear in the $ form_values.

分类:Web 时间:2010-10-25 人气:205
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.039 (s). 11 q(s)