I have a custom ajax form in a custom module, the form function code is over 400 lines so it's too big to post here, but hopefully I can explain the situation clearly here.
The form has a form function mymodule_form($form, &$form_state)
and also an ajax callback attached to a button mymodule_ajax_callback($form, $form_state)
. I put a dpm($form_state['values'], 'form state values from form function);
in mymodule_form
function, and also dpm($form_state['values'], 'form state values from callback');
inside the mymodule_ajax_callback
function.
Now when I change the values in the form, and press the ajax'd button, the form state values from the form function only has 1 element in the array, and that's the button that was pressed. All other values are missing. At the same time, the form state values from ajax callback function has all the form fields with the correct values. If I understood ajax forms in D7 correctly, you're meant to change the form inside the form function and only do return render($form['element'])
from the ajax callback. This situation makes it impossible to do so as I can't access all the values from the form function.
There's nothing in the Recent Log Messages about ajax errors. The form has only 1 Ajax button, but it has also 1 ajax'd select dropdown which when changed, changes options for another select dropdown.
I'm currently sitting here scratching my head, ready to pull some hair out wondering what could cause such weird behavior.
I'm posting a screenshot of the dpm's for clarification:
As you can see values from form function has 1 element in array, values from ajax callback has 56 elements in array.
When I change the Ajax'd select dropdown however, the form state values from form function shows 55 elements, which is probably correct:
So it's only when I use the Ajax button this weird behavior occurs. Any help greatly appreciated. Can post the form code if needed.