0

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..

mysite.com/search?cat=2$coutry=3

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

0

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. – Tanvir Ahmad 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. :) – Tanvir Ahmad 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. – Tanvir Ahmad Aug 15 '14 at 10:05
  • Actuly I am done with this too.. '#default_value' => $params['cat']. :) – Tanvir Ahmad 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.