Question

I created a html page and create form on it . I want send data of my form to a form that I create . I use session but when I use session and refresh page , other session was delete or when i use session_unset(); the sessions in 4 or 5 time refresh age was show .

What is the right way for save session for anonymous users?

I use $_SESSION['test'] but I think that it's not good way .

Was it helpful?

Solution

If you get form content that is outdated since 4 or 5 refreshes this could be a caching issue. You can try to add a cache context to the form:

$form['#cache']['contexts'][] = 'session';

Or if this doesn't help disable the render cache for the form:

$form['#cache']['max-age'] = 0;
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top