I am developing a custom module with the ability to store data on an external database using Drupal 7 Form API. I started with the multistep form example, added few more steps and other fields.
To implement the ability to edit those data I created a class that retrieves returns an array suitable to fill the $form_state['values'] element in order to have a default value for each form element. Here follows the code I have in the form callback when going to edit my data:
if( !empty($form_state['build_info']['args'][0]) ) ) {
$a = new ind();
$a->get_ind( $form_state['build_info']['args'][0] );
$form_state['values'] = get_object_vars($a);
unset($a);
}
Problem is when I hit the previous/next buttons because of the form is being rebuilt always with the data from the class so every change in a field is lost when hitting "Previous"; suddenly every change gets lost when I click "Next" after "Previous" (fields are empty!).
How do you achieve editing with multistep form with existing data? I am stuck here attempting to put the code above at submit and previous handlers with no success.