0

I have a problem returning table and form in page callback at the same time it only works if one of them only returned.

function _table_maps(){
$query = db_select('maps','m');

$result = $query->fields('m')
                ->extend('TableSort')
                ->extend('PagerDefault') 
                ->limit(50)
                ->execute(); 

$header = array('Title','Longitude','Latitude','Description');

$rows = array();
while($data = $result->fetchAssoc())
{
    $rows[] = array(
        $data['maps_title'],
        $data['maps_long'],
        $data['maps_lat'],
        $data['maps_desc']
    );
}

$output = theme_table(
            array(
                "header" => $header,
                "rows" => $rows,
                "attributes" => array(),
                "sticky" => true, 
                "caption" => "",
                "colgroups" => array(),
                "empty" => t("Table has no row!")
                )
            ).theme("pager");

return $output;

}

function aieadmin_map_form($form_state){

$form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the Title For the Location'),
);

$form['long'] = array(
    '#type' => 'textfield',
    '#title' => t('Longitude'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the Longitude For the Location'),
);

$form['lat'] = array(
    '#type' => 'textfield',
    '#title' => t('Latitude'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the Latitude For the Location'),
);

$form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Describe it'),
    '#cols' => 60,
    '#rows' => 5,
    '#description' => t('Location description.'),
);

$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));

return $form; 
}

/*******Page Callbacks********/

function aieadmin_callback_mod(){
$page = _table_maps();
$page .= drupal_get_form('aieadmin_map_form');
return $page;
}
  • can you return table and form separately? – Serjas Sep 21 '12 at 4:10
0

try this in the form

$custom_table = _table_maps();

$form['some_information'] = array(
  '#markup' => $custom_table,
  '#prefix' => '<div class="custom-class">',
  '#suffix' => '</div>',
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.