0

We have the form from where we need to access the values through a php code written. But $_POST is not working in drupal.

We need to know how to access all the submit values in php, please can anyone help us ?...

Arun
  • 47
  • 1
  • 7
  • Check out this related question: http://stackoverflow.com/questions/5819479/drupal-form-ahah-element-problem-with-empty-post. Quoting: "´drupal_get_form()´ saves the ´$_POST´ array into ´$form['#post']´" – AJJ Jun 29 '12 at 07:22

1 Answers1

1

Is this a form rendered in Drupal and also read from Drupal? Then it's easy with the FAPI. You just need to add a submit callback to the form.

If it's your own module's form, just create another function with _submit suffix, like mymodule_form_function_submit. If it's someone else's form you will need to implement hook_form_alter and have it add your submit callback like so:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'the_form') {
    $form['#submit'][] = 'mymodule_the_form_submit';
  }
}

Then simply implement the callback function.

function mymodule_the_form_submit($form, $form_state) {
  die('My name is ' . $form_state['values']['name']);
}

Using Drupal's built in Form API has the added benefit of separate validation from business logic. This means you can also add a validate callback, just like you addeed a submit one. If the validate callback calls form_set_error() then your submit callback won't even get called and so it can safely rely on having proper data.

Clive
  • 36,918
  • 8
  • 87
  • 113
Tobias Sjösten
  • 1,084
  • 9
  • 16