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') 
                               .   ))
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.


Jaypan’s picture

What is the purpose of doing an insert in your validate function? Validation functions should only be used for validation, not for submission.

Amjad_dokhan’s picture

You're right Jaypan. I found out that I don't need the validate function after all. I removed it and relocated everything under the submit function. Now the code works. Thank you very much again ! Have a good day