The submit function is where you should be executing your code. If you are executing your code in the ajax callback, you are probably doing it wrong. The ajax callback should only return what is needed to be returned. You can use logic to check things in the form generation function (like checking variables to change parts of the form), but any logic needed to be run on form submit, should be done in the form submit function/s.
function myform_example_form($form, &$form_state) {
$form = array();
$form['submit'] = array(
'#type' => 'submit',
'#prefix' => '<div id="myform">',
'#suffix' => '</div>',
'#ajax' => array(
'callback' => 'myform_example_ajax_callback',
'wrapper' => '#myform',
),
'#submit' => array(
'myform_example_submit',
),
);
}
function myform_example_submit($form, &$form_state) {
// do stuff here.
}
function myform_example_ajax_callback($form, &$form_state) {
return $form['submit'];
}
If you really need to stop the submit function on a submit button you can do it by setting #executes_submit_callback.
eg.
function myform_example_form($form, &$form_state) {
$form = array();
$form['submit'] = array(
'#type' => 'submit',
'#prefix' => '<div id="myform">',
'#suffix' => '</div>',
'#ajax' => array(
'callback' => 'myform_example_ajax_callback',
'wrapper' => '#myform',
),
'#submit' => array(
'myform_example_submit',
),
'#executes_submit_callback' => FALSE,
);
}