Why doesn't loading a form in the view header work?
sEntity forms should be built using the entity.form_builder service. You'll need an entity to work with, for a node your code might change to something like this:

$node = \Drupal::entityTypeManager()
  -&gt;getStorage('node')
  -&gt;create(['type' =&gt; 'page']);

$form = \Drupal::service('entity.form_builder')-&gt;getForm($node);

print \Drupal::service('renderer')-&gt;render($form);


As noted in the comments, this won't actually work in the context you're using it, regardless of how you render the form. The views_php area handler renders the output of the custom PHP using #markup, which will strip out the &lt;input&gt; and other form tags. You'll need a custom or contributed module, or to alter the views_php module directly, to make this work.

Here's a simple area handler that adds support for common form tags:

&lt;?php

namespace Drupal\foo\Plugin\views\area;

use Drupal\Component\Utility\Xss;
use Drupal\views_php\Plugin\views\area\ViewsPhp;

/**
 * Views area PHP text handler with support for common form tags.
 *
 * @ingroup views_area_handlers
 *
 * @ViewsArea("foo")
 */
class ViewsPhpForm extends ViewsPhp {

  public function render($empty = FALSE) {
    if (!$empty || !empty($this-&gt;options['empty'])) {
      $content = $this-&gt;renderViewsPhp($this-&gt;options['content']);
      $form_tags = ['form', 'input', 'select', 'fieldset', 'option', 'button', 'textarea', 'optgroup'];
      $allowed_tags = array_merge(Xss::getAdminTagList(), $form_tags);

      return [
        '#type' =&gt; 'inline_template',
        '#template' =&gt; Xss::filter($content, $allowed_tags),
      ];
    }

    return [];
  }

}


This code should be in src/Plugin/views/area/ViewsPhpForm.php and will need updating for the name of your module.

You'll also need to make views aware of it with a hook either in your .module file, or foo.views.inc:

/**
 * Implements hook_views_data().
 */
function foo_views_data() {
  $data['views']['php_with_form'] = [
    'title' =&gt; t('PHP with form'),
    'help' =&gt; t('Use PHP code with support for form tags.'),
    'area' =&gt; [
      'id' =&gt; 'foo',
    ],
  ];

  return $data;
}


After a cache rebuild you'll be able to add a new area handler, PHP with form, and your form should be rendered.