Hi,

I my module, I've created a form that works perfectly when #method value is get - I access parameters with $_GET array.

When I change this value to post, I can't retrieve parameters with $_POST array - it is empty.

I think this is due to the type of item I have set in my hook menu :

    $items[] = array(
      'path' => 'result_page',
      'title' => 'Search results',
      'callback' => 'results',
      'access' => true,
      'type' => MENU_CALLBACK
    );

The action parameter value of my form is result_page.
The $_POST array is read in results function.

Any idea?

Thanks,
Sylvain

Comments

depace’s picture

can you post ur form code...

sdelbosc’s picture

   function my_module_forms() {
  
    $forms = array();
    
    // classic search box
    $forms['searchbox_form'] = array( 
      'callback' => 'searchbox_formbuilder', 
      'callback arguments' => array('searchbox'), 
    );
    
    return $forms;
    
  }

  function searchbox_formbuilder($form_id) {
  
    $form = array();
    
    // common parts
    $form['#action'] = 'result_page';
    $form['#method'] = 'post';
   
    // query field
    $form['query'] = array(
      '#type' => 'textfield',
      '#default_value' => $_POST['query'],
    );
    
    // submit button
    $form['sa'] = array(
      '#type' => 'submit',
      '#value' => t('GO'),
    );
    
    return $form;
    
  }
  
  function results() {

    // retrieve the query parameter
    if ( $_POST['query'] == '' ) {
      drupal_set_message(t('No query parameter found.'), 'error');
      print theme('page', '');
      return;
    }
    
  // ...

  }
  
  function theme_my_module_block($formId) {

    // Which searchbox has to be displayed
    switch ($formId) {

      case 0 :
        $output = drupal_get_form('searchbox_form');
        break;
        
    }

    return $output;
    
  }

Acquia
Cahors, FRANCE

sdelbosc’s picture

It was simply a huge error!

Somebody else working on the same project had overrided my 'formbuilder' function.

Really sorry and thank you very much Dipesh for your response.

Sylvain

Acquia
Cahors, FRANCE