我自己写个模块,是为扩展user module的,是扩展后台编辑用户资料的表单,代码如下:
.install文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php function user_recommend_install() { db_query ( ' ALTER TABLE {users} ADD COLUMN {star_selected} TINYINT DEFAULT 0 NOT NULL , ADD COLUMN {pingce_selected} TINYINT DEFAULT 0 NOT NULL ' ); } function user_recommend_uninstall() { db_query ( ' ALTER TABLE {users} DROP COLUMN {star_selected} , DROP COLUMN {pingce_selected} ' ); } |
.module文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
function user_recommend_form_user_profile_form_alter(& $form , & $form_state ){ $form [ ' star_selected' ] = array ( '#type' => 'checkbox' , '#title' => t( '是否推荐他呢?' ), '#weight' =>-6, ); $form [ ' pingce_selected' ] = array ( '#type' => 'checkbox' , '#title' => t( '是否选择这个?' ), '#options' => 1, '#weight' =>-6, ); $form [ '#submit' ][] = 'user_recommend_configure_submit' ; } function user_recommend_configure_submit( $form ,& $form_state ){ kpr( $form ); exit ; } |
提交后页面报错,
但是我去掉这个模块,一切正常,请问哪里写错了?应该怎么解决呢?
你的form_alter里面的表单元素有问题,建议找到现成
你的form_alter里面的表单元素有问题,建议找到现成的作为模板,复制、粘贴修改。
'#options' => 1,这里就有问题。
'#options'
=> 1,
这里就有问题。嗯,后来我找到原因了,今天看到你的解决办法,是一样的,谢谢
嗯,后来我找到原因了,今天看到你的解决办法,是一样的,谢谢!