Get current URL arguments inside ajax callback? I have created custom module called 'mymodule'.

In this URL localhost/es/mymodule/name/1/2/3, I have this field:

$form['name'] = array(
  '#title' =&gt; t('Enter name'),
  ...
  '#ajax' =&gt; array(
    'event' =&gt; 'blur',
    'callback' =&gt; 'mymodule_ajax_callback',
    'wrapper' =&gt; 'my-wrapper',
    'method' =&gt; 'replace',
  ),
  ...
);


My ajax callback is successfully called:

function mymodule_ajax_callback($form, &amp;$form_state) {
  ...
  return ...
}


However, inside 'mymodule_ajax_callback', I need to get the current URL arguments of the page such that arg(1) = 'name', arg(2) = 1, arg(3) = 2, and so on.

By nature, Drupal uses the URL system/ajax so calling arg(N) does not work as I need it to be.

How to get the current URL arguments using arg() inside the ajax callback?



EDIT 1:

I thought of using $_SESSION[...] = arg(1); $_SESSION[...] = arg(2); ... on my form and calling the session variables on my ajax callback. But I am looking for a better way without using session but only using drupal methods if available.
The arguments passed to the page callback are saved in $form_state['build_info']['args'], with the exception of the form ID.

If you use the following definition for the menu item, you would get them there. (Replace 'form ID' with the form builder ID.)

$item['name/%/%/%'] = array(
  // …

  'page callback' =&gt; 'drupal_get_form',
  'page arguments' =&gt; array('form ID', 1, 2, 3),

  // …
);


References


drupal_get_form()
drupal_build_form()