1

I am opening a simple dialog box from Ajax, using the following code-

var exportActionDialog = Dialog.ajax({
  dialog: dialogSettings,
  dialogType: 'modal',
  type: 'POST',
  url: '/web/admin/crm/export-dialog',
  data: { whatever: 'itworking' },
  progress: { type: 'throbber'}
});
exportActionDialog.execute();

The dialog actually opens successfully and displays the form associated with the url.

But I can't get the value of the whatever post variable.

When I do this

Public function buildForm(array $form, FormstateInterface $form_state) {
$whatever = $this->getRequest()->request->get('whatever');

dpm($whatever); // returns null

The $whatever variable returns as null.

Now the actual reason I want to use a post is because I want to pass an array which can contain up to 1000 elements or more. Doing this using Get makes the url unreasonably long.

Just hoping someone could point me in the right direction?

Pls any clues guys?

Thanks...

1 Answer 1

1

You have to replace the data key with submit. Drupal.ajax() transfers the submit key to the data key of $.ajax() but ignores a data key already set:

var exportActionDialog = Drupal.ajax({
  dialog: dialogSettings,
  dialogType: 'modal',
  httpMethod: 'POST',
  url: '/web/admin/crm/export-dialog',
  submit: { whatever: 'itworking' },
  progress: { type: 'throbber'}
});
exportActionDialog.execute();

Similar the legacy jQuery type key, now method, where Drupal is using httpMethod. In this case no problem, POST is default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.