I want to define a session in contributed module (field collection module) in drupal 7 when the page is loaded.

This session takes a value from the URL and fill one of the field that depend on it. I defined a session in the form_alter function but I need to refresh the page to let the session take the value? So, could anyone tell me where I can define it? In which function of the module?

  • In which function of the module? see How to run check on each page load? – No Sssweat Feb 19 '17 at 5:20
  • in field_collection_form_alter function. – user3859372 Feb 19 '17 at 5:32
  • I checked the link that you post it. The suggest to use MYMODULE_boot() function. I try to use it but without any success. I think I cannot use this function in contributed module. – user3859372 Feb 19 '17 at 5:34
  • which contrib module? – No Sssweat Feb 19 '17 at 5:35
  • field collection module – user3859372 Feb 19 '17 at 5:41

You can use the session that Drupal creates. Just add your data to an element of the $_SESSION variable:

$_SESSION['my_module']['some_key'] = 'some value';

It will

| improve this answer | |
  • I use this in field_collection_form_alter function but I need to refresh the page to set the session. In which function that I can use it to set the session when page is loaded? – user3859372 Feb 19 '17 at 5:31
  • You don't need to. Drupal already initiates the session. – Jaypan Feb 19 '17 at 5:33
  • Sorry.. But it which file I have to add this session. Does this work if I want to set the node id in the session when the user edit the node? – user3859372 Feb 19 '17 at 5:44
  • You can see it in hook _form_alter like you have already done. – Jaypan Feb 19 '17 at 5:46
  • The session is saved. But the session is set after the page is build. Is there a way to set the session when the page is loaded? – user3859372 Feb 19 '17 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.