Drupal Studs help me with my form_alter hook ( I am almost there)
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 !
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.
精彩评论