I am creating a simple form, when sumits, shows result from an external API. But URL remain the same, so you cant get a url if your search result and send it to someone.

But when I use get

$form['method'] = 'get';

It shows a construted url..


But it donot fetch the result, cause it is bypassing the submit and validation functions. Any help?


Have the page or form check for the presence of your variables, using drupal_get_query_parameters(), and if present, perform validation checks and get results from the external API, and display.

For example,

$params = drupal_get_query_parameters();
if ( isset($params['cat']) ) {
  //validate $params['cat']
    if ( myValidationCheck($params['cat']) ) {
      $results = myExternalAPIGetResults($params['cat']);
      $form['results'] = myResultsDisplay($results);
  • Thanks for the reply. This is somwhow working for me. But two issues, 1. I cant figure if form is submitted or not, like -if (!empty($form_state['submitted']))- 2. After submit click, form field value cahnged to default, not the one I selected to see result. e-g If I select, CAT01 from Category, and default is CAT, it changes back to CAT. Aug 15 '14 at 0:34
  • Also it works for me only if I use it inside where I am creating form, cz no validate or submit works, but that's fine for me. :) Aug 15 '14 at 0:35
  • What exactly are you trying to accomplish?
    – faerysteel
    Aug 15 '14 at 0:38
  • Ok, Ignore point 1 but point 2. When I submit CAT1 from dropdown(SelectField) with default 'CAT', It changes back to CAT. It shuold remain CAT1 as it is showing the result of. Aug 15 '14 at 10:05
  • Actuly I am done with this too.. '#default_value' => $params['cat']. :) Aug 15 '14 at 10:12

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.