0

I want to call custom functions for doing some profile filed updation on user registration. So i used to implement my custom functions in hook_form_alter. The code is here

<?php
function calculation_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'user_register':
$form['#validate'][1] = 'do_database_updation';
break;
}
return $form;
}

function do_database_updation($form, &$form_state){
/* perform database updation here... */
}

It works fine, but the problem is when the validation fails, the database updation cannot be retrieved back. I want to call the custom function after validate the input values. How it to do ?

3

You can add your function in the [#submit] key. For example :

if ( empty($form['#submit']) ) {
  $form['#submit'] = array();
}
array_push($form['#submit'], 'do_database_updation');

The submit handler is called after the validation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.