Drupal Studs help me with my form_alter hook ( I am almost there)

放肆的年华 提交于 2019-12-02 12:09:30

问题


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!'); } }


回答1:


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 !




回答2:


RedBen is right, content profile may be a better solution.

It seems like you're adding the second submit handler in a strange way - it's simply the name of a function, not an array. Have you checked that your submit handler is running?

Because the reference to the handler is a simple string, you just need to append it to the array using

$form['#submit'][] = '_module_registration_submit'

If you need it to run before the standard handler, use array_unshift to push it onto the beginning of the #submit array.



来源:https://stackoverflow.com/questions/3017759/drupal-studs-help-me-with-my-form-alter-hook-i-am-almost-there

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!