Exchanging variables across hook_form_validate and hook_form_submit

Dear everyone,

I have a module with “mymodule_form_validate” and “mymodule_form_submit” functions. I have a “db_insert” function inside “mymodule_form_validate”. I retrieve the last SQL id number in “mymodule_form_validate” but I need to take it to “mymodule_form_submit function”.

function mymodule_form_validate($form, &$form_state) {
global $message_index;
$message_index = db_insert('pm_index') 
                      ->fields(array( 
                               .
                               .   ))
                  ->execute();
dpm($message_index); // <-- This prints out the last SQL id
}

function mymodule_form_submit($form, &$form_state) {
global $message_index;
dpm($message_index); // <-- This does not print out 
}

How can I make $message_index global and accessible by all functions ? Any help is very much appreciated. Thank you very much in advance.

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed