How to get form values in URL as keys of an array I have a custom form with min and max price value:

    $form['price']['min'] = [
      '#type'          =&gt; 'hidden',
      '#default_value' =&gt; isset($_GET['price']['min']) ? $_GET['price']['min'] : '',
      '#attributes'    =&gt; ['id' =&gt; 'price-min'],
    ];

    $form['price']['max'] = [
     '#type'          =&gt; 'hidden',
     '#default_value' =&gt; isset($_GET['price']['max']) ? $_GET['price']['max'] : '',
     '#attributes'    =&gt; ['id' =&gt; 'price-max'],
    ];


and I would like the URL after the form is submitted to look like this:

/search?price%5Bmin%5D=5000&amp;price%5Bmax%5D=10000


but actually it's coming out like this:

/search?min=5000&amp;max=10000


How can I get the form values to appear in the URL in the required format?
Try adding:

$form['price']['#tree'] = TRUE;


This tells the form builder you want to nest field names. Otherwise it will just use the most immediate element keys for the field names, as you have found.

This is actually useful behaviour most of the time, as it means you can group fields in containers such as fieldsets without affecting their name attributes.