How to show a custom form in a block? I have a custom form which currently shows on a page. The form is submitted via ajax and the view embedded is also updated via ajax. I do not want to show the form on a page. Instead I want to show it in a block. I should be able to put the block anywhere on the website.

This is my form

/**
 * Provide a form.
 */
function MYMODULE_form($form, &amp;$form_state) {

  $form['wrapper'] = [
    '#type'       =&gt; 'container',
    '#attributes' =&gt; [
      'id' =&gt; 'mywrapper',
    ],
  ];

  $form['wrapper']['node_form'] = [
    '#type'  =&gt; 'fieldset',
    '#title' =&gt; t('Add article'),
  ];

  $form['wrapper']['node_form']['node_title'] = [
    '#type'     =&gt; 'textfield',
    '#title'    =&gt; t('Article title'),
    '#required' =&gt; TRUE,
  ];

  $form['wrapper']['submit'] = [
    '#type'   =&gt; 'submit',
    '#value'  =&gt; t('Save'),
    '#submit' =&gt; ['MYMODULE_form_submit'],
    '#ajax'   =&gt; [
      'callback' =&gt; 'MYMODULE_MYCALLBACK',
      'wrapper'  =&gt; 'mywrapper',
    ],
  ];

  $form['wrapper']['view_display'] = [
    // view machine name &amp;&amp; display/block name
    '#markup' =&gt; views_embed_view('nodes', 'block'),
  ];

  return $form;
}

/**
 * Do some validation.
 */
function MYMODULE_form_validate($form, &amp;$form_state) {
  // Better do some validation.
  // Here or via #element_validate.
  // @see https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7.x#element_validate
}

/**
 * Form submit. Node creation.
 */
function MYMODULE_form_submit($form, &amp;$form_state) {

  global $user;
  $node = new stdClass();

  $node-&gt;type     = 'article';
  $node-&gt;title    = $form_state['values']['node_title'];
  $node-&gt;language = LANGUAGE_NONE;
  $node-&gt;uid      = $user-&gt;uid;

  node_object_prepare($node);
  node_save($node);

  // Empty out title field on rebuild.
  $form_state['input']['node_title'] = '';

  // Rebuild form.
  $form_state['rebuild'] = TRUE;
}

/**
 * Ajax callback to return the whole wrapper.
 */
function MYMODULE_MYCALLBACK($form, &amp;$form_state) {

  return $form['wrapper'];
}

/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {

  $items['example/form'] = [
    'title'            =&gt; 'Example Form',
    'description'      =&gt; 'A form to mess around with.',
    'page callback'    =&gt; 'drupal_get_form',
    'page arguments'   =&gt; ['MYMODULE_form'],
    'access arguments' =&gt; ['create article content'],
  ];

  return $items;
}
Create a block with hook_block_info and embed your custom form within a block using hook_block_view. Assuming module's name to be example, this module creates a "My block" with the form. 

FYI, in the below code drupal_render(drupal_get_form('MYMODULE_form')); is the one rendering your form in the block where MYMODULE_form is the form ID.

 &lt;?php
    /**
     * Implements hook_block_info().
     */
    function example_block_info() {
      $blocks = array();

      $blocks['MYBLOCK'] = array(
        'info' =&gt; t('My block'), 
        'cache' =&gt; DRUPAL_NO_CACHE,
      );
      return $blocks;
    }

    /**
     * Implements hook_block_view().
     */
    function example_block_view($delta = '') {
      $block = array();

      switch ($delta) {
        case 'MYBLOCK':
          $block['subject'] = t('My block title');
          $block['content'] = drupal_render(drupal_get_form('MYMODULE_form'));
      }
      return $block;
    }