Reputation: 41
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 ?...
Upvotes: 0
Views: 2445
Reputation: 1094
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.
Upvotes: 1