Hi All,
I haven't found any information whether this is a correct "drupal way" to use drupal_render functions to show some pages. I want to simply show form elements like in this function
$form = array(
'#type' => 'textfield',
'#title' => 'O rany rany jestem niepokonany',
'#default_value' => 'Ha i pe ha o pe bez reszty oddany',
);
return drupal_render($form);
I do not want to create form with all its functions (i.e. I do not want to use drupal_get_form). I am asking about this because after patching using a patch from simpletest I get notices like
Notice: Undefined offset: 0 in form_get_error() (line 834 of /var/www/p2portal/includes/form.inc).
Notice: Undefined index: #name in theme_textfield() (line 2053 of /var/www/p2portal/includes/form.inc).
Notice: Undefined index: #id in theme_textfield() (line 2053 of /var/www/p2portal/includes/form.inc).
which in fact come from the fact that these attributes are not set by bare drupal_render function. These notices are not visible without the simpletest patch but are generated anyway (installing simpletest patch just make them visible to the user).
Should I set #id and #name attributes manually and then use drupal_render? Or should I use drupal_get_form (which in fact is ineffective, since I want to render those elements)? Or maybe I should just turn off showing notices in production environment? Or is it simpletest bug?
Comments
It's a bad idea not to use
It's a bad idea not to use the in-built form API to create forms, why can you not use drupal_get_form?
But it's inefficient
I just want to present the user some information and I want to use drupal form elements to show it. No submit button and stuff like that. Using drupal_get_form performs other tasks which are not needed for me.
Then what should be the "correct way" to present information using the drupal form elements? Make a theme for specific page and include those elements in a theme?
It's a question a bit about "standards" I think..
OK I get what you mean,
OK I get what you mean, this'll work:
You need add in those few extra field attributes (name, id, value) so they get populated, and the #parents to surpress an error you'd get otherwise.