So, here is much more graceful solution!
After some analyses of steps, maked above, I decided, that only thing we need to make ajax form, loaded by ajax, to work is fill javascript Drupal.settings array with correct data, describing forb behavior. In the above example we made it by hands, with hardcode, whitch is not true. Obviously, somewhere in drupal code it work does automatically. I found this place. It is function ajax_pre_render_element in the ajax.inc. It gives array of any form element with ajax property and appends to it additional parameters, which will be converted to JS code and added to Drupal.settings array later. Exactly thing, that we need.
Here is my code now:
function anyform_block_info()
{
//standart form for displaying to user
$blocks['any_form'] = array(
'info' => t('Any form'),
'status' => true,
'region' => 'content',
'weight' => 99,
'visibility' => 1
);
//hidden 'form' needed to generate and load ajax behavior settings before form loading
$blocks['faq_form_hidden'] = array(
'info' => t('Any fake form'),
'status' => true,
'region' => 'footer', //I thing, it will be better place it in footer^ in my case content is ajaxed
'weight' => 99,
'visibility' => 1
);
return $blocks;
}
function anyform_block_view($delta)
{
switch ($delta) {
case 'faq_form':
$block['content'] = drupal_get_form('anyform'); //standart form
return $block;
case 'faq_form_hidden':
$block['content'] = anyform_get_hidden_form(); //fake form
return $block;
break;
}
}
function anyform_get_hidden_form()
{
$form = drupal_get_form('faqform'); //give our original form
$form = ajax_pre_render_element($form['submit']); //create settings for element with #ajax property (don't pass whole form as argument - not works)
//makes fake form with hidden element in footer, but with correct array with settings for ajax behavior
$fakeform['fakeform'] = array(
'#type'=>'markup',
'#markup'=>'<div style="display: none;"></div>',
'#attached'=>$form['#attached'], //our magical array
);
return $fakeform;
}
So, I hope, it will solve most of your problems with drupal ajax-loaded forms. For me this solution works without any problems, and I going sleep being happy =^_^= Good luck!