继续Drupal分享精神 QQ群:107748121 站长QQ:2275288328 skype: hellodrupal【drupal交流+drupal 建站+theme制作】
登录 注册

定义page,使用Hook_menu 调用form表单小例子

一个简单的例子,定义一个page,然后调用自己的定义的form 表单。

<?php

/**
* Hook menu
* 定义page,调用自定义的form 表单
*/

function modulename_menu(){//使用Hook menu 来定义个url 衔接,就是一个page

 
$items = array(); //定义item 数组
$items['test/%'] = array(  //结构化数组 % 代表参数,可以任意。
   
'title' => t('payment'), // page title dispaly in HTML title t() 主要适合翻译多语种
   
'description' => t('payment'),
   
'page callback' => 'my_form', // 调用form函数
   
'access arguments' => array('access content'), //权限 ,默认系统权限,当然你可以自定义权限
   
'type' => MENU_CALLBACK, //菜单类型
 
);
    return
$items; //返回值
}


function
my_form() { //定义form函数
return drupal_get_form('test_payment_form'); //使用drupal_get_form 来处理结构的form数组,然后呈现到html里显示
}

function
test_payment_form($form_state){//定义form结构化数组

       
$form['mobile'] = array(
     
'#title' => t('mobile'),
     
'#type' => 'textfield',
   
'#required' => TRUE,

     
'#description' => t('Please enter mobile.'),
     
'#weight' => 4,
    );
 
$form['submit'] = array(
   
'#type' => 'submit',
   
'#value' => 'Save',
  );

return
$form;
}
?>

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.