欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

How do I alter the form submission handler? hook form submit alter

shiping1 的头像
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

For some reason I need to replace some characters (if exist) in every single textfields in any form just right before they stored in database. In other words I need a hook in which I could get all submitted data and replace their characters.
I found this solution:

function hook_form_alter($form, $form_state, $form_id) {
  $form['#submit'] = 'my_custom_submission_function';
}

But this isn't a good idea since I have to take care of the rest of the submission progress too. I just need to replace some characters. Is there any hook to do this? What are the solutions?

shareimprove this question
 add comment

$form['#submit'] stores an array of form submit handlers. With the code you provided you're overwriting it by adding only your own. To get the result you want you should add your submit handler as the first element in the array like this:

array_unshift($form['#submit'], 'mymodule_custom_submission');

Getting the right values in the right forms and replacing some characters is probably a bigger issue in itself. You may want to narrow down the forms/fields you need to change to make sure you don't break anything.

shareimprove this answer
 add comment
function zad_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'search_block_form') {
        $form['actions']['submit']['#value'] = 'Press Here To save';
    }
}
shareimprove this answer


来自 http://drupal.stackexchange.com/questions/18641/how-do-i-alter-the-form-submission-handler
普通分类: