Drupal #ajax callback executing twice I am creating a custom paginator in Drupal 7. 

The paginator is working fine, the only problem is that every time I click to the next page button, increases the step in 2 (For example I can see pages 0,2,4,6,etc...)and that's because the submit button is executed twice and increases the number of the page by two.

As you can see in the callback I use AJAX to replace two different sections on the page, and that might be the cause.

Any idea?

Submit function:

function club_paginator_form_submit($form, &amp;$form_state) {
$values = $form_state['values'];

if ($form_state['triggering_element']['#value'] == '&gt;')
{
    $form_state['values']['current_page'] = intval($form_state['values']['current_page'])+1;
}
else
{
    $form_state['values']['current_page'] = intval($form_state['values']['current_page'])-1;
}

$form_state['rebuild'] = TRUE;


}

Forms:
(...)

$form['next'] = array(
    '#name' =&gt; 'paginator-next',
    '#type' =&gt; 'submit',
    '#value' =&gt; t('&gt;'),
    '#weight' =&gt; 5,
    "#ajax" =&gt; array(
        "callback" =&gt; "ajax_club_paginator_next",
        "effect" =&gt; "fade",
    ),
    '#prefix' =&gt; '&lt;div id="club-paginator-page-replace"&gt;'.$page.'&lt;/div&gt;',
    '#attributes' =&gt; array('class' =&gt; array('button')),
    '#submit' =&gt; array('club_paginator_form_submit'),
);


(...)

Callback:

function ajax_club_paginator_next($form, &amp;$form_state)
{
    $page = intval($form_state['values']['current_page']);

    $html = '';
    $html .= '&lt;div id="club-paginator-content-replace"&gt;';
    $html .= draw_clubes_page($page);
    $html .= '&lt;/div&gt;';

    $paginator = '&lt;div id="paginator"&gt;';
    $form = drupal_get_form('club_paginator_form', $page);
    $paginator .= drupal_render($form);
    $paginator .= '&lt;/div&gt;';

    return array(
        '#type' =&gt; 'ajax',
        '#commands' =&gt; array(
            ajax_command_replace("#club-paginator-content-replace", $html),
            ajax_command_replace("#paginator", $paginator)
        )
    );
}
I Finally found the error...

drupal_get_form was calling the submission again, I was creating a new form like the one I was substituing, but I was also updating the old.

Instead of creating a new form, I just used the $form variable instead of drupal_get_form.

Please find the new logic below!

function ajax_club_paginator_next($form, &amp;$form_state)
{
    $page = intval($form_state['values']['current_page']);

    $html = '';
    $html .= '&lt;div id="club-paginator-content-replace"&gt;';
    $html .= draw_clubes_page($page);
    $html .= '&lt;/div&gt;';

    $paginator = '&lt;div id="paginator"&gt;';

    //Not Needed!
    //$form = drupal_get_form('club_paginator_form', $page);

    $paginator .= drupal_render($form);
    $paginator .= '&lt;/div&gt;';

    return array(
        '#type' =&gt; 'ajax',
        '#commands' =&gt; array(
            ajax_command_replace("#club-paginator-content-replace", $html),
            ajax_command_replace("#paginator", $paginator)
        )
    );
}