Lose ability to use node load with an argument in ajax form submit I have a basic form like this, that is literally just a submit button:

function mymodule_form($form, &amp;$form_state) {
    $form = array();

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Submit'),
        '#ajax' =&gt; array(
            'callback' =&gt; 'mymodule_form',
        ),
    );

    return $form;
}


The form uses Drupal's built in #ajax feature, and calls back to itself because nothing is supposed to change after the submit button is clicked.

I also have this form submit function that submits that form:

function mymodule_form_submit(&amp;$form, &amp;$form_state) {
    $node = node_load(arg(1));

    $query = db_merge('mydatabase')
    -&gt;key(array('nid' =&gt; $node-&gt;nid))
    -&gt;fields(array(
        'nid' =&gt; $node-&gt;nid,
        'column1' =&gt; 'value1',
    ))
    -&gt;execute();
}


This form submit should, in theory, add the current nodes ID to the 'nid' column of mydatabase, and 'value1' to the 'column1' column. The form submit correctly adds 'value1' to my 'column1', however it adds NULL to my 'nid' column every time. But ONLY when ajax is enabled on the form. When ajax is disabled, it correctly submits the node ID. Which leads me to believe there is either an issue with using node_load in an ajax form submit, or using arg(1) in an ajax form submit.

Any advice would be appreciated.
I ended up finding a solution to this. Essentially, instead of trying to load the arg(1) inside the mymodule_form_submit (because apparently you can't do that when the submit is triggered via ajax), I instead passed the node ID to the form submit through a hidden form field. See below:

function mymodule_form($form, &amp;$form_state) {
    $form = array();

    $form['node'] = array(
        '#type' =&gt; 'hidden',
        '#value' =&gt; arg(1),
    );

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Submit'),
        '#ajax' =&gt; array(
            'callback' =&gt; 'mymodule_form',
        ),
    );

    return $form;
}


function mymodule_form_submit(&amp;$form, &amp;$form_state) {
    $node = node_load($form['node']['#value']);

    $query = db_merge('mydatabase')
    -&gt;key(array('nid' =&gt; $node-&gt;nid))
    -&gt;fields(array(
        'nid' =&gt; $node-&gt;nid,
        'column1' =&gt; 'value1',
    ))
    -&gt;execute();
}


And now it works just fine.