I've got a strange problem. I've been working with the Drupal 7 form API which was going swimmingly. For some reason or other I cleared the Drupal cache, and now the form simply says 'array' - it was working fine before. No matter what I change I cannot seem to make any form using the API display. I have used the code used in the Drupal Form API quickstart guide, which still says 'array'. I am calling it using print render(drupal_get_form('my_form')), but I have also tried drupal_render. If I print_r the drupal_get_form part it shows the array, so the form is definately there. I'm at a loss, please tell what is wrong!
function urban_form($form, &$form_state) {
$form = array();
$form['customization'] = array(
'#type' => 'fieldset',
'#title' => 'ur:customization',
'#collapsible' => TRUE
);
$form['customization']['check_in'] = array(
'#title' => t("Check in"),
'#type' => 'select',
'#options' => array(
'one' => 'Option 1',
'two' => 'Option 2',
'three' => 'Option 3',
)
);
$form['customization']['length'] = array(
'#title' => t("Please select length of stay"),
'#type' => 'select',
'#options' => array(
'one' => 'Option 1',
'two' => 'Option 2',
'three' => 'Option 3',
)
);
return $form;
}
print drupal_render(drupal_get_form('urban_form'));
Comments
I don't see anything
I don't see anything immediately wrong with your form array or the calls, but there's a chance that there's some funky namespace collisions in there. If your module is called urban then a function called urban_form will get picked up by hook_form which is used by node modules. Check out http://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/... I don't know that that's definitely the cause of your problem but nothing else really comes to mind. What happens if you rename your function to something like "urban_form_builder" or something like that? Anything?
Also, make sure you've flushed your caches a couple of times. It could just be a caching issue. Hope this helps.
http://bonify.io
Before I read your reply I
Before I read your reply I managed to fix it by changing the name of the form, so you you were right! Strange that it was working before I cleared the cache though...
For me it was ... I have
For me it was ... I have missed the 'drupal_render' :)
I saw this problem
I saw this problem too.
this code does't work.
I'm not sure what context
I'm not sure what context you're using this in but try changing
to:
return '<div id="same-id">' . drupal_render(drupal_get_form('user_login_block')) . '</div>';
and see if that helps any. In D7 drupal_get_form returns a renderable array, not HTML.
http://bonify.io
getting same error
''.drupal_render(drupal_get_form('test_form',$ap_code)).'';
In D7 drupal_get_form returns a renderable array, not HTML.
drupal_render(drupal_get_form(id)) not working
I don't know why but
does not work in my case to render a custom form in a block or node using PHP code text format.
Instead it works the following code