I'm trying to embed custom form (only file upload item, will attach the code below). But I see only inner stuff like divs and inputs. No form tag at all.

In page callback I use function that calls theme. here's hook_menu() and page callback

    $items['invite/%'] = array(
      'page callback' => 'invite_page_content',
      'page arguments' => array(1),
      'access callback' => 'invite_check_access',
      'access arguments' => array(1),

    $output = array(
      '#theme' => 'invite_view',
      '#type' => 'markup',
      '#content' => array(
        'g_id' => $g_id,
        'g_name' => $g_name,
        'user' => $user,

    return $output;

In theme file I have call of the form

    $attachment_form = drupal_get_form('invite_attachment_form');
    echo render($attachment_form);

Here's form function

    function invite_attachment_form($form, &$form_state) {
      $form['attachment'] = array(
        '#type' => 'managed_file',
        '#name' => 'upload_attachment',
        '#title' => t('Attach additional file?'),
        '#upload_location' => 'public://email-attachments/',
        '#upload_validators' => array(
          'file_validate_size' => array(2 * 1048576),
          'file_validate_extensions' => array(
            'png gif jpg jpeg mp4 ogg avi mov wmv flv ogv webm txt pdf zip rar',

      return $form;

Any help appreciated!


I've found what was the reason for such behavior. There is some script in my site that deletes first form element. So if I add before my form render - everything will be ok. Need to find what is it.

  • Have you tried it with a default theme from core to see if it still happens?
    – acrosman
    May 7 '18 at 18:07
  • @acrosman, Thanks for the tip, will try and let you know May 8 '18 at 7:34
  • @acrosman Tried it with default theme and it works. Do you know what it could be? May 8 '18 at 7:39
  • By now you probably figured out the reason I asked: once you know it works in the default themes and not your own, you know your theme is the most likely cause and therefore the place to search.
    – acrosman
    May 10 '18 at 18:40
$attachment_form = drupal_get_form('invite_attachment_form');
echo drupal_render($attachment_form); //That should work 

see https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_get_form/7.x

  • Thanks for the answer, but unfortunately it does not work :( May 8 '18 at 7:38

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.