[development] Form adding query parameters

Steven Jones steven.jones at computerminds.co.uk
Fri Oct 1 08:50:27 UTC 2010


Hi Nancy,

The actual redirection of forms is handled by drupal_redirect_form:
http://api.drupal.org/api/function/drupal_redirect_form/6

Which looking at the code, passes the $form_state['redirect'] to drupal_goto.

drupal_goto has a second argument for the query string, so I think the
end of your form submit function may want to look something like:

drupal_set_message("going to $r");
$form_state['redirect'] = array($_GET['q'], array('query' => $r));
drupal_set_message(print_r($_SESSION, true));

Hope that helps!

Regards
Steven Jones
ComputerMinds ltd - Perfect Drupal Websites

Phone : 024 7666 7277
Mobile : 07702 131 576
Twitter : darthsteven
http://www.computerminds.co.uk



On 30 September 2010 20:34, nan wich <nan_wich at bellsouth.net> wrote:
> I have a function that is working fine with query parameters to filter the
> data, but the customer wants a form to enter the date selections. The form
> is no problem. But just to make  it easier for me, I want the form to set
> the query parameters and return to the orignal function (menu item) so I
> don't have to re-code a lot.
> function stats_form_submit($form, &$form_state) {
>   $start = implode('-', $form_state['values']['start_date']);
>   $end = implode('-', $form_state['values']['end_date']);
>   $g = $_GET;
>   unset($g['q']);
>   $g['start'] = $start;
>   $g['end'] = $end;
>   $r = '';
>   $sep = '';
>   foreach ($g as $key => $value) {
>     $r .= "$sep$key=$value";
>     $sep = '&';
>   }
>   drupal_set_message("going to $r");
>   $form_state['redirect'] = url($_GET['q'], array('query' => $r));
>   drupal_set_message(print_r($_SESSION, true));
> }
> When I do this several weird things happen. First, there is an extra slash
> in the URL; i.e. instead of "stats/6?end=8-31-2010", I get
> "/stats/6?end=8-31-2010" (of course with the usual garbagy encoding). I
> don't know if that is the reason, but te second problem is that the tid (6
> in this example) passed from the menu now includes the query string, making
> it fail the numeric test and not setting $_GET['end'].
>
>
>
> Is there a better, safer way to return the submitted form data as a query
> string?
>
>
>
> Nancy
>
>
>
> Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King,
> Jr.


More information about the development mailing list