First, thanks for your reply. I have a form that captures a patient_id and stores info about the patient in session variables. The user is then forwarded to a second form where the session variables are used to populate some of the fields. The second form is quite complex because some of the fields are used to create a node while other values are stored in separate database tables (e.g. - medications). Everything works fine, but when I try to use unset() to removed the session variables, it doesn't work. Could you tell me where I could unset the variables in the second form? Is there a specific hook I should use?
Using a timeset is an idea but it might give conflict because within the time the session might get destroyed while still in the process or live longer than you want it to be.
In the form_submit handler (I guess your using a hook for this to insert within your custom tables) you can use unset() on the needed vars after you've done all the saving and just before using drupal_goto() (or whatever handler).
If it doesn't work, can you post some code snippet and tell me where in the process it is?
I tried to use unset() in hook_submit and in hook_insert but it doesn't seem to work. I set the session variable in one form and then redirect the user to a second form. The first form is a custom form and the second form is used to create nodes (custom content type).
I am also wanting to unset $_SESSION variable in submit handler function, with no success.
Any idea what could get this to work?
My submit handler looks like:
function my_module_my_hidden_field_submit_handler($form, &$form_state) {
unset($_SESSION['my-values']);
$_SESSION['my-values'] = $form_state['values']['my-hidden-field'];
}
I was excited initially when I got my submit function to store the $_SESSION variable successfully...but now I don't understand why I can't update the $_SESSION variable.
I finally figured out that my problem was related to using hidden input type. Specifically, on click of the submit button, I am updating the value of the hidden field via jquery. I can see the value update on click, but it does not get processed with this value.
But when I use a text field input type, it seems to work fine. Note: different browsers behave differently with hidden fields. With Firefox, I couldn't even seem to change the value with jquery. I could, however, with Chrome. So - my issue was unrelated to unset of $_Session variables.
Comments
Please provide some more
Please provide some more detail. What is your code, what did you try and where does it go wrong?
Normally unset() should be working fine.
unset() problems
First, thanks for your reply. I have a form that captures a patient_id and stores info about the patient in session variables. The user is then forwarded to a second form where the session variables are used to populate some of the fields. The second form is quite complex because some of the fields are used to create a node while other values are stored in separate database tables (e.g. - medications). Everything works fine, but when I try to use unset() to removed the session variables, it doesn't work. Could you tell me where I could unset the variables in the second form? Is there a specific hook I should use?
This might help:
http://www.rymland.org/en/blogs/boaz/2_jan_09/making-php-session-expire-...
Thank you, arvana.
Thank you, arvana.
Using a timeset is an idea
Using a timeset is an idea but it might give conflict because within the time the session might get destroyed while still in the process or live longer than you want it to be.
In the form_submit handler (I guess your using a hook for this to insert within your custom tables) you can use unset() on the needed vars after you've done all the saving and just before using drupal_goto() (or whatever handler).
If it doesn't work, can you post some code snippet and tell me where in the process it is?
unset() of session variables
I tried to use unset() in hook_submit and in hook_insert but it doesn't seem to work. I set the session variable in one form and then redirect the user to a second form. The first form is a custom form and the second form is used to create nodes (custom content type).
Very weird.. Isn't it
Very weird.. Isn't it possible to put a different var within the session like $_SESSION['myVar'] = 0. Also an ugly solution, I know.
Hope anyone else knows something for this issue..
Also dealing with this issue
I am also wanting to unset $_SESSION variable in submit handler function, with no success.
Any idea what could get this to work?
My submit handler looks like:
I was excited initially when I got my submit function to store the $_SESSION variable successfully...but now I don't understand why I can't update the $_SESSION variable.
I only have one session variable
and I used $_SESSION = array(); to unset it and it works.
I figured out my problem was related to using hidden field
I finally figured out that my problem was related to using hidden input type. Specifically, on click of the submit button, I am updating the value of the hidden field via jquery. I can see the value update on click, but it does not get processed with this value.
But when I use a text field input type, it seems to work fine. Note: different browsers behave differently with hidden fields. With Firefox, I couldn't even seem to change the value with jquery. I could, however, with Chrome. So - my issue was unrelated to unset of $_Session variables.