By maori on
hi guys
i,ve searched around but couldnt find out how to accomplish this with D7 in D6 i had
function mymodule_form_award ($form, &$form_state) {
$checkboxes = array();
//changed below to meet D7 way
$rows = "SELECT * FROM awards WHERE awardtype='small'"; // this is a typical query from the node table to get some info about nodes
$result = db_query($rows);
foreach($result as $row)// = db_fetch_array($rows)) // we loop through the results
{
$checkboxes[$row->AWARD_ID] = ''; // a blank value is given so that the checkboxes have no title and are just rendered as a blank checkbox
$form['DESCRIPTION_display'][$row->AWARD_ID] = array('#value' => $row->DESCRIPTION);
$form['DESCRIPTION_' . $row->AWARD_ID] = array ("#type" => "value", "#value" => $row->DESCRIPTION);
$form['award_imag_display'][$row->AWARD_ID] = array ("#value" => $row->award_imag);
$form['award_imag_' . $row->AWARD_ID] = array ("#type" => "value", "#value" => $row->award_imag);
$form['reason'][$row->AWARD_ID] = array('#type' => 'textfield', '#required' => True, '#maxlength' => 255, '#size' => 100, '#value' => $row->reason,'#default_value' => '');
};
$form['date'] = array(
'#title' => t('Date of award'),
'#type' => 'date',
'#description' => t('Enter the Date of awardl'),
'#required' => TRUE,
'#default_value' => array(
'year' => format_date(time(), 'custom', 'Y'),
'month' => format_date(time(), 'custom', 'n'),
'day' => format_date(time(), 'custom', 'j')
)
);
$form['user']['feed_item_length']= array (
'#title' => t ( 'Assign to User'),
'#type' => 'select',
'#required' => TRUE,
'#default_value' => variable_get('feed_item_length','teaser'),
'#options' => array(
'teaser'=> t('--------'),
''=>_users(),
)
);
$form['checkboxes'] = array
(
'#type' => 'checkboxes',
'#options' => $checkboxes,
'#required' => True,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add AWARD'),
);
$form['#theme'] = 'mymodule_theme';
return $form;
}
function mymodule_theme()
{
return array
(
'mymodule_theme' => array
(
'arguments' => array('form' => NULL),
),
);
}
function theme_mymodule_theme($form)
{
$has_posts = isset($form['DESCRIPTION_display']) && is_array($form['DESCRIPTION_display']);
$select_header = $has_posts ? theme('table_select_header_cell') : '';
$header = array(theme($select_header) , t('Description'), t('IMAGE'), t('Default Reason'));
$output = '';
if ($has_posts)
{
$rows = array();
foreach(element_children($form['checkboxes']) as $award_id)
{
$row = array();
$row[] = drupal_render($form['checkboxes'][$award_id]);
$row[] = drupal_render($form['DESCRIPTION_display'][$award_id]);
$row[] = drupal_render($form['award_imag_display'][$award_id]);
$row[] = drupal_render($form['reason'][$award_id]);
$rows[] = $row;
}
}
else
{
$header = array(t(''), t(''));
$row = array();
$row[] = array
(
'data' => t('No awards were found'),
'colspan' => 2,
'style' => 'text-align:center',
);
$rows[] = $row;
}
$output .= theme('table', $header, $rows); // this builds our table
$output .= drupal_render($form); //this calls some last rendering functions on the $form from the form definition in the original function
return $output;
}
and i get
Notice: Undefined index: render element in theme()
can any one point me where i went wrong please
Comments
ok seems theres another
ok
seems theres another problem aswell :(
if i rem out $form['#theme'] = 'mymodule_theme';
i get this error
which comes from
well aculy i get a simmiler error for the
aswell
ok fixed the Notice:
ok fixed the
Notice: Undefined property: stdClass::$AWARD_ID
problems seems the code made them lower case :D
but still getting the orginal problem of
Notice: Undefined index: render element in theme()
and also i get
Fatal error: Maximum function nesting level of '100' reached, aborting!
solved the Fatal error:
solved the
Fatal error: Maximum function nesting level of '100' reached, aborting!
problem D7 changed the render part
ie
and that gives me no more errors however the whole sites theme is messed up and everything is displayed down the left side :(
looking here http://drupal.org/update/modules/6/7#element_theme_properties
helped solve the problem however i cant really understand about the #theme_wrappers ie how to use them to solve my issue
ok and that gives me no more
ok
i think i solved that issue changed
to
and it looks like it sorted out the problem of everything being shown on the left hand side ie sites main theme is left intact but it just steps over the foreach statement in the
function theme_mymodule_theme($form)
so nothing is displayed on the page :(
i see in netbeans that $form is showing as NULL so that explains why but not how as stepping though the form function it all goes as it should and if i rem out the $form['#theme'] = 'mymodule_theme';
it displays all the form elements and the txt pulled from the database so something is up with my theme sections but i'am lost :(
any hints ??
okidoki i got it displaying
okidoki
i got it displaying now :) heres what i have so far
yes this works 'arguments'
yes this works
'arguments' => array('form' => NULL),this line is not required as the
'render element' => 'form', suplies the required form element to your theme
Thank you!
drupal_render_children() is a function I needed to find. I was upgrading my module to Drupal 7 and when I called drupal_render() in my theme function I was receiving a PHP memory exceeded error.
The call
How are you calling your function from the template file?
print theme('your_theme', drupal_get_form('my_form'));or
print drupal_render(drupal_get_form('my_form'))There is a cleaner way..
removed...
use: <?phpdrupal_render(drupa
use:
Here is another function
Here is another
But i get the error
Notice: Undefined index: render element in theme() (line 835 of C:\xampp\htdocs\drupal\includes\theme.inc).
Notice: Undefined index: #title in theme_bookmark_author_percentage_role()
Templating/Theming form
Templating/Theming form should be in the way,
Instead of using the theme key(
#theme) directly in form