[development] Form adding query parameters

nan wich nan_wich at bellsouth.net
Thu Sep 30 19:34:31 UTC 2010


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100930/01ecd2b8/attachment.html 


More information about the development mailing list