How can I get $_POST data in a callback?

Solutions

They access $_POST in the same way other functions do.

Take file_ajax_upload() as example; it contains the following code.

  if (empty($_POST['form_build_id']) || $form_build_id != $_POST['form_build_id']) {
    // Invalid request.
    drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
    $commands = array();
    $commands[] = ajax_command_replace(NULL, theme('status_messages'));
    return array('#type' => 'ajax', '#commands' => $commands);
  }

The function is a page callback defined in file_menu().

  $items['file/ajax'] = array(
    'page callback' => 'file_ajax_upload', 
    'delivery callback' => 'ajax_deliver', 
    'access arguments' => array('access content'), 
    'theme callback' => 'ajax_base_page_theme', 
    'type' => MENU_CALLBACK,
  );
Tags: Routes

Similar questions

using $_POST values in form alter to add validation
it's not the first time that i get into trouble using $_post in a node form alter, this time i'd like some assistance. basically, i need to pass some parameters to a form (and i should not pass the appended to the url, as query parameters). but $_POST values don't work as expected (they work until reaching validation phase). So.. in a page i pass a...
Drupal form ahah element, problem with empty $_POST
I'm making a module for ubercart. It's nearly finished, but now I'm working on the admin page. I want the admin to be able to add options, like the poll module adds choices. The problem I have is that the admin form is generated through drupal_get_form, which leaves the $_POST empty. $_POST['form_build_id'] seems to be needed to get the form from c...
$_POST undefined from remote server POST
I am writing a Drupal 7 module which is listening for HTTP POST messages to be sent by a 3rd party remote application. For testing I am sending messages using the Firefox Poster extension. If I POST the message, the following code fails to place any value in my local vars (I get 'undefined index'): However, if I send the message using GET, the vars...
drupal_mail - Need to Remove $_POST
I am new to the drupal_mail function and need help. The code I have works, but I want to get rid of the $_POST parameter to limit my security holes. I don't know how to get the posted variables without using the $_POST parameter, and ideally, I would like to single each parameter out to put a custom label on it. Any help would be greatly appreciate...
Drupal 7 - undefined variable _POST error in export_ui
Our Drupal 7 site has suddenly begun generating this error warning: Undefined variable: _POST in require_once() (line 1 of /home/website/public_html/sites/all/modules/ctools/plugins/export_ui/ctools_export_ui.class.php). We hadn't made any changes or updates prior to this happening, which is why it is puzzling, if not worrying. What is also puzzlin...
Upload file does not show up in $_POST or $_FILES, only $HTTP_RAW_POST_DATA
I am trying to add an async upload to my Drupal 6 custom module. The problem is, though, that when the upload occurs (I have a break point on my php function) no data can be seen in $_POST or $_FILES. All the data for the file gets put into $HTTP_RAW_POST_DATA. I would expect it to be in the $_FILES array. Can anyone tell me what I'm doing wrong. O...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.