<?php
/**
* Implements hook_element_info().
*/
function example_element_info() {
$types = array(
'example' => array(
'#input' => TRUE,
'#tree' => TRUE,
'#process' => array('example_process'),
'#theme' => array('example'),
'#pre_render' => array('form_pre_render_conditional_form_element'),
'#value_callback' => 'example_value_callback'
)
);
return $types;
}
/**
* element显示前对element内参数的处理
*/
function example_process($element, $form_state) {
if(isset($element['default_value'])) {
$element['#default_value'] = $element['default_value'];
}
return $element;
}
/**
* element呈现的模板
*/
function theme_example($variables) {
$output = '<input name="example" type="text" value=""/>';
return $output;
}
/**
* from submit后,element的最终值
*/
function example_value_callback($element, $input = FALSE, &$form_state) {
if ($input !== FALSE) {
// element可以由多个element组成,但只有一个返回值,其他element将不返回
return $_POST['example'];
} elseif (!empty($element['#default_value'])) {
return $element['#default_value'];
}
return;
}
/**
* Implements hook_theme().
*/
function example_theme() {
return array(
'example' => array(
'render element' => 'element',
)
);
}
function example_menu()
{
$items = array();
$items['test_element'] = array(
'title' => 'Example',
'page callback' => 'drupal_get_form',
'page arguments' => array('example_form'),
'access callback' => TRUE,
'expanded' => TRUE,
);
return $items;
}
function example_form($form, &$form_state) {
$form = array();
$form['example'] = array(
'#type' => 'example',
'#title' => 'example',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit'
);
return $form;
}
function example_form_submit($form, &$form_state) {
drupal_set_message('value: '.$form_state['values']['example']);
}
/**
* Implements hook_element_info().
*/
function example_element_info() {
$types = array(
'example' => array(
'#input' => TRUE,
'#tree' => TRUE,
'#process' => array('example_process'),
'#theme' => array('example'),
'#pre_render' => array('form_pre_render_conditional_form_element'),
'#value_callback' => 'example_value_callback'
)
);
return $types;
}
/**
* element显示前对element内参数的处理
*/
function example_process($element, $form_state) {
if(isset($element['default_value'])) {
$element['#default_value'] = $element['default_value'];
}
return $element;
}
/**
* element呈现的模板
*/
function theme_example($variables) {
$output = '<input name="example" type="text" value=""/>';
return $output;
}
/**
* from submit后,element的最终值
*/
function example_value_callback($element, $input = FALSE, &$form_state) {
if ($input !== FALSE) {
// element可以由多个element组成,但只有一个返回值,其他element将不返回
return $_POST['example'];
} elseif (!empty($element['#default_value'])) {
return $element['#default_value'];
}
return;
}
/**
* Implements hook_theme().
*/
function example_theme() {
return array(
'example' => array(
'render element' => 'element',
)
);
}
function example_menu()
{
$items = array();
$items['test_element'] = array(
'title' => 'Example',
'page callback' => 'drupal_get_form',
'page arguments' => array('example_form'),
'access callback' => TRUE,
'expanded' => TRUE,
);
return $items;
}
function example_form($form, &$form_state) {
$form = array();
$form['example'] = array(
'#type' => 'example',
'#title' => 'example',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit'
);
return $form;
}
function example_form_submit($form, &$form_state) {
drupal_set_message('value: '.$form_state['values']['example']);
}