How to register a session var within a form_submit()
kidata - May 8, 2008 - 07:29
I've builded a working form using the Form API, in my submit handler function i want to register a value into the session to get access to that value outside the form processing:
function protected_files_login_form_submit($form_id, $form_values) {
...
$_SESSION["protected_files_user_".$node->nid] == $form_values["protected_user"];
...
}this doesn't work - the session only holds values from the form processing.
How can i pass a value from inside the form submit function to the main program logic?
Is there any possibilty to define a e.g. callback to the submit function?
This makes me really stuck! Anybody can help?

==
Should be = I think. I store session vars like this frequently, it works fine.
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
Refer example
Refer example given.
http://drupal.org/node/227103
This should explain everything
Hope this will help.
Cheers.
Naveen P.L.
no success
Thanks for your example, i do it just in the same way - but i can't add any value to the session.
I've tried another test:
function protected_files_login_form_submit($form_id, $form_values) {global $myTestVar;
$myTestVar = "success";
// ... setting the session vars etc ...
}
// outside the function ..
echo "testvar: " . $myTestVar;
The value of $myTestVar is also empty.
Could be the problem, that i'm executing the function in a theme file (node-event.tpl.php) not in a module?
But other declarations of values to the session work fine (in main program logic of theme file).
Change function name
Change function name to
protected_files_login_form_overview_submit for submit
protected_files_login_form_overview for your form
protected_files_login_overview for 'type' => MENU_LOCAL_TASK,
protected_files_login_form_overview_validate for your form validation.
if $form['myTestVar'] is the name of your input form then try echo $form_values['myTestVar']; on your submit function. I think this will work.
Hope this will help.
Cheers.
Naveen P.L.