0

I have a form on a Drupal 7 site, which is submitted using the GET method to refresh the page's display using the query parameters.
One of the parameters uses the select box, with the multiple option. This results in the query parameter using the format option%5B%5D=39&option%5B%5D=54

Is there a way to have the form submit and merge the query parameters into something like option=39+54

0

I am not sure if this is gonna work, but I think it might help you a little bit.

$query = explode('&', $_SERVER['QUERY_STRING']);
$combined = '';

foreach($query as $key => $value) {
  if ($key == 'option') {
    $combined .= $value;
  }
}

drupal_goto($_SERVER['REQUEST_URI'] . '&option=' . $combined);
  • Using a drupal_goto risks breaking any additional form functionality or other listeners in the chain. – Kevin Jan 3 at 18:29
  • Thanks for the suggestion, I am trying not to do a redirect after the form submission so that there isn't 2 redirects. I was hoping their might be a process to hook into during the form processing to manipulate how the values are encoded but I can't seem to find anything in the FAPI documentation that might help. – inertiahz Jan 3 at 19:34
0

This is the solution that I have working at the moment, although I am not sure if this is the correct way to do this.

First is that instead of loading the form into my render array with drupal_get_form() I have now used drupal_build_form() which seems to allow GET method forms to use the validate and submit form hooks.

Then in the submit hook have $form_state['redirect'] to a custom formatted URL which is cleaner for end users.

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.