Form processing issue while generating a dynamic form and preparing via API calls directly How can I fix the processing and submission of forms that I am preparing and rendering dynamically via API calls.

function drupal_set_confirmation($message, array $options, array $escape=array(), $type='warning', $details=NULL){
    $form = array();

    $form['title'] = array(
    '#markup' =&gt; '&lt;h3&gt;' . t($message) . '&lt;/h3&gt;'
    );

    if (!empty($details)) {
        switch(gettype($details))   {
            case 'string':
                $form['details'] = array(
                    '#markup' =&gt; $details,
                );
            break;
            case 'array':
                $form['details'] = $details;
            break;
        }
    }

    if (!empty($options)) {
        $form['options'] = array(
            '#type' =&gt; 'container',
            '#attributes' =&gt; array('class' =&gt; array('user-confirmation-options')),
        );

        foreach($options as $key =&gt; $option) {
            $form['options'][$key] = array(
                '#submit' =&gt; array($option['callback']),
                '#type' =&gt; 'submit',
                '#value' =&gt; $option['title'],
                '#attributes' =&gt; $option['attributes'],
            );
        }

        if (!empty($escape)) {
            $form['options']['escape'] = array(
                '#markup' =&gt; l($escape['title'], $escape['path']),
            );
        } else {
            $form['options']['escape'] = array(
                '#markup' =&gt; l(t('Cancel'), current_path()),
            );  
        }
    }

    $form_state = form_state_defaults();
    $form_id = 'form_user_confirmation';

    drupal_prepare_form($form_id, $form, $form_state);
    // I do not see any reason to call drupal_process_form while serving the form.
    //drupal_process_form($form_id, $form, $form_state);
    $rendered_form = drupal_render($form);
    return drupal_set_message($rendered_form, $type);
}


And it works greatly to show a dialog form of my own choice by calling.

drupal_set_confirmation(t('Do you really want to suicide?'), array(
        'okay' =&gt; array(
        'callback' =&gt; '_yes_kill_me',
        'title' =&gt; t('Yes'),
        'attributes' =&gt; array('class' =&gt; array('button', 'tiny')),
    ),
    ), array(
        'title' =&gt; t('No'),
        'path' =&gt; current_path(),
    ));


And callback function as #submit handler for a particular element is not invoked.

How can I fix the form processing and submission issue using this approach to work?
I fixed it this way, it started to invoke form submit handlers.

function MODULE_init() {
    if (!empty($_POST) &amp;&amp; $_POST['form_id'] == 'form_user_confirmation') {
        $form_state = form_state_defaults();
        $form_id = 'form_user_confirmation';
        drupal_build_form($form_id, $form_state);
    }
}