I created a custom module named my_module.

In hook_menu() I define the following path.

$items['my-module/item'] = array(
  'title' => 'Item',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('my_module_item_form'),
  'access arguments' => array('access item content'),

This is the code for my_module_item_form().

$arg = arg(1); // Problem here! Should return "item", right?
// $form[...] = array('#ajax' => ...);

$form['arg'] = array(
  '#type' => 'hidden',
  '#value' => $arg,
  // I also tried '#default_value'

// Submit field

Basically, I really need to obtain item in arg(1) and nothing else.

When I edit fields (not fields with ajax) and click submit, I can obtain the correct arg(1) in my hook_submit which is "item". Now, when I edit fields with ajax and click submit, arg(1) returns "ajax" which I do not like.

How should I obtain "item" in arg(1) in in the form submission handler during an ajax call in my form?


When implementing AJAX in a form, it will send a callback to system/ajax, if you didn't set your path in the AJAX properties. So, when you use arg(1) in your code, it will return ajax, which is the value assigned to the hidden form field.

| improve this answer | |
  • What is the workaround to my problem? – Neigyl R. Noval Apr 27 '13 at 6:15
  • Could you share your complete code? – Jayendra Kainthola Apr 27 '13 at 7:45
  • 1
    @NeigylR.Noval There isn't a workaround; even if you would set #ajax['path'], the path would change, and arg(1) would return a value different from the one you are expecting. – kiamlaluno Apr 28 '13 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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