开发者

form with no form_id(Drupal 6.x)

开发者 https://www.devze.com 2023-01-31 21:50 出处:网络
I have this form placed inside a block and it is assigned to right region of my site. Form is displayed just fine. But the submit button doesn\'t work as intended - to call submit function. So, I did

I have this form placed inside a block and it is assigned to right region of my site. Form is displayed just fine. But the submit button doesn't work as intended - to call submit function. So, I did som开发者_如何学JAVAe debugging and found an anomaly that there is no essential data - such as form_id and tokens - drupal normally injected to every form. As I can't figure out the root cause of this, I'm here for pointers of friends from here. Here's an excerpt of my code -

function mymodule_block($op = 'list', $delta = '', $edit = array()) {

switch ($op) {
    case 'list':
        $blocks['quick_search'] = array(
            'info'       => t('Quick Search'),

        );
    return $blocks; 

    case 'view':
        switch ($delta) {
            case 'quick_search':
                $block['subject'] = t('Quick Search');
                $block['content'] = drupal_get_form("block_quick_search");
            break;        
        }

    return $block;
}


}


function block_quick_search(&$form_state){
$form = array();
.
.
.
    $form['quick_search_submit'] = array(
        '#type' => 'submit',
        '#value' => t('Search'),        
        '#submit' => array('mymodule_quick_search'),
    );                              

    return $form;   

}

function mymodule_quick_search($form, &$form_state){

drupal_goto($base_path,"..............");   
}

Thanks in advance


there is no essential data - such as form_id and tokens

This is indeed the reason why form submissions are not processed correctly. Check whether drupal_prepare_form is called on your form and whether it adds those items correctly. It is called by drupal_get_form if he form is not posted (and thusly not retrieved from the cache).

If $form['#token'] and $form['form_id'] are added correctly, I suspect something is wrong with translating the form to HTML. Do you use any custom theming for the form?


Try to pass your submit handler to the main form and not on the item submit like that:

$form['#submit'][] = 'mymodule_quick_search';

it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消