Drupal Studs帮助我的form_alter钩子(我几乎在那里) [英] Drupal Studs help me with my form_alter hook ( I am almost there)

查看:97
本文介绍了Drupal Studs帮助我的form_alter钩子(我几乎在那里)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



目标是在正常的用户注册表中添加更多的字段,将其设置为小,然后提交它存储额外的字段在一个表。



这是我到目前为止。有人可以给我最后的轻推,让我走。请帮帮我。另外如何应用一些较小的样式,如排列新的表单字段?



非常感谢你!!!!!!!!!



  function module_menu(){
$ items = array();
$ items ['school / registration'] = array(
'title'=>'升级注册表',
'page callback'=>'module_school_register',
'键入'=> MENU_CALLBACK

);



return $ items;
} //函数结束



function module_school_register(){
return drupal_get_form('form_school_register');
} //函数结束



function module_school_form_alter(& $ form,$ form_state,$ form_id)
{



dsm($ form_id);



if($ form_id =='user_registration_form')
{
//修改#submit表单属性前缀另一个提交处理程序数组
$ form ['#submit'] = array_merge(
array('_ module_registration_submit'=> array()),
$ form ['#submit']
);



}
}



function _module_registration_submit($ form_id,$ form_values){
//存储不同表中的额外数据
}



function module_registration_validate($ form,& ; $ form_state)
{
$ error = 0;
//验证这里的东西,如果发生错误,将$ error设置为true,否则你想这样做。完全由你在你如何设置错误。
if($ error)
{
form_set_error('new_field_name','AHH SOMETHING WRONG!');
}
}

解决方案

建议您在滚动自己的解决方案之前,先看看内容配置文件模块。



您可以为学校注册定义自定义内容类型(节点),添加您的cck字段,并将其作为内容配置文件激活。在内容配置文件设置上,然后在用户注册表单上激活它。零代码!


So I think I am almost there conceptually but need some missing pointers.

Objective is to add a few more fields to the normal user registration form, style it a little, then submit it with storing the extra fields in a table.

This is what I have so far. Can someone give me the final nudge and get me going. Please help me. Also how do I apply some minor styling like aligning the new form fields ?

Thank you so much !!!!!!!!!

  function module_menu() {
$items = array();
$items['school/registration'] = array(
      'title' => 'Upgraded Registration Form',
      'page callback'    =>'module_school_register',
      'type' => MENU_CALLBACK
);

return $items; }//end of the function

function module_school_register(){ return drupal_get_form('form_school_register'); }//end of the function

function module_school_form_alter(&$form, $form_state, $form_id) {

dsm($form_id);

if ($form_id == 'user_registration_form') { // modify the "#submit" form property by prepending another submit handler array $form['#submit'] = array_merge( array('_module_registration_submit' => array()), $form['#submit'] );

} }

function _module_registration_submit($form_id, $form_values) { // store extra data in different table }

function module_registration_validate($form, &$form_state) { $error=0; //Validation stuff here, set $error to true if something went wrong, or however u want to do this. Completely up to u in how u set errors. if ($error) { form_set_error('new_field_name', 'AHH SOMETHING WRONG!'); } }

解决方案

I suggest you have a look at content profile module before rolling your own solution.

You define your a custom content type (node) for your school registration, add in you cck fields, and activate it as a content profile. On content profile settings, you then activate it on user registration form. Zero code !

这篇关于Drupal Studs帮助我的form_alter钩子(我几乎在那里)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆