简体   繁体   中英

how to get values in php from the submit form in drupal

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM