How to preserve form values for user who navigates out of form and back? I have a form that works, essentially, as a search / filter:

 foreach($search_properties as $property) {
    $form['properties'][$property-&gt;idProperty] = array(
      '#title' =&gt; $property-&gt;Label,
      '#ajax' =&gt; array(
        'callback' =&gt; 'mymodule_filter_ajax',
        'wrapper' =&gt; 'category-filter-result',
        'method' =&gt; 'replace',
        'effect' =&gt; 'fade',
      )
    );
    switch ($property-&gt;PropertyType) {


Options are generated by taking only actually used values from possible ones:

  '#options' =&gt; array_intersect_key($possible_choices, $used_values),
  '#default_value' =&gt; array_keys($used_values),


Nothing interesting here, really, just set of fields that, on change, reloads a list of links using AJAX. Never submitted, never saved.

Problem is - when user clicks on a link, and then clicks browser's "back", all fields have their defaults selected again.

I'm under impression that it was not the case with Views exposed filters. I think I remember these filters was able to keep values when user went back to them. So it is possible.

What is the Drupal way to keep user-selected values in the simple scenario of a link click, and then browser's "back" button?
I'm not aware of a specifically Drupal way to do it.

As I say, I find that if I fill out a form, don't submit, click a link, and then click back, the form elements are still populated, unless perhaps there's some AJAX/JS funkiness going on with them (the actual form elements). However a little digging suggests that's browser-dependent and won't work in certain situations (eg. over HTTPS). I'd love to know more about this behaviour.

I think ideally you'd use JS to put the data in the URL. If you don't need to support older browsers then you can use the History API (not that I ever have...) which would allow you to separate arguments in a more Drupally way: eg. path/arg1/arg2/arg3. Otherwise the traditional window.location.hash can be used instead.

You can use the session variable like Views, which is more flexible and simpler to implement, but can cause anonymous users to bypass caching.