I'm at an absolute loss as to how display a table and a form on the same page.
My objective is to publish information comparing our user data with our billing gateways data. My first thought was to create a dummy form item that can have it's values replaced by the submit handler akin to this Table and Form in the same page but that didn't appear to work with my callback.
My next attempt was to create a embedded form that upon a successful submission callback replaced information in the original render array. The idea of the code is to publish the 'one' in all the values before the submit button is called and 'two' after it is called. Here is that code:
function test_lookup_page($email = NULL){
$hinput = array('One Customer Information' => 'aci', 'Two Customer Information' => 'uci');
$header = array(
'Legend' => array(
'data' => t('Legend'),
'id' => 'head-legend',
'class' => 'col-legend',
),
);
foreach ($hinput as $hkey => $hvalue){
$ckey[$hkey] = array(
'data' => $hkey,
'id' => 'head-' . $hvalue,
'class' => 'col-' . $hvalue,
);
$header = array_merge($header, $ckey);
}
// Table rows
$rows = array(
array(
// Column 1
'customer' => array(
'data' => t('Customer Account'),
'id' => 'row1-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'first',
'id' => 'row1-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'first',
'id' => 'row1-uci',
'class' => 'col-uci',
),
),
array(
// Column 2
'billing' => array(
'data' => t('Billing'),
'id' => 'row2-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'first',
'id' => 'row2-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'first',
'id' => 'row2-uci',
'class' => 'col-uci',
),
),
array(
// Column 3
'shipping' => array(
'data' => t('Shipping'),
'id' => 'row3-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'first',
'id' => 'row3-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'first',
'id' => 'row3-uci',
'class' => 'col-uci',
),
),
array(
// Column 1
'subscription' => array(
'data' => t('Subscription(s)'),
'id' => 'row4-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'first',
'id' => 'row4-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'first',
'id' => 'row4-uci',
'class' => 'col-uci',
),
),
);
$build = array(
'header_text' => array(
'#type' => 'markup',
'#markup' => '<p>' . t('To add additional content to a form page, you can use a page callback and return a render array like this.') . '</p>',
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
),
'test_order_admin_form' => drupal_get_form('test_order_admin_settings', $email),
);
return $build;
}
function test_order_admin_settings($form, &$form_state, $email = NULL) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#submit' => array('test_order_lookup'),
);
return ($form);
}
function test_order_lookup($form, &$form_state) {
$hinput = array('One Customer Information' => 'aci', 'Two Customer Information' => 'uci');
$header = array(
'Legend' => array(
'data' => t('Legend'),
'id' => 'head-legend',
'class' => 'col-legend',
),
);
foreach ($hinput as $hkey => $hvalue){
$ckey[$hkey] = array(
'data' => $hkey,
'id' => 'head-' . $hvalue,
'class' => 'col-' . $hvalue,
);
$header = array_merge($header, $ckey);
}
// Table rows
$rows = array(
array(
// Column 1
'customer' => array(
'data' => t('Customer Account'),
'id' => 'row1-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'second',
'id' => 'row1-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'second',
'id' => 'row1-uci',
'class' => 'col-uci',
),
),
array(
// Column 2
'billing' => array(
'data' => t('Billing'),
'id' => 'row2-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'second',
'id' => 'row2-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'second',
'id' => 'row2-uci',
'class' => 'col-uci',
),
),
array(
// Column 3
'shipping' => array(
'data' => t('Shipping'),
'id' => 'row3-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'second',
'id' => 'row3-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'second',
'id' => 'row3-uci',
'class' => 'col-uci',
),
),
array(
// Column 1
'subscription' => array(
'data' => t('Subscription(s)'),
'id' => 'row4-legend',
'class' => 'col-legend',
),
'One Customer Information' => array(
'data' => 'second',
'id' => 'row4-aci',
'class' => 'col-aci',
),
'Two Customer Information' => array(
'data' => 'second',
'id' => 'row4-uci',
'class' => 'col-uci',
),
),
);
$build = array(
'header_text' => array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
),
);
return ($build);
}