Skip to main content
SOLVED
Source Link
que le
  • 71
  • 2
  • 2
  • 8
controller contains: public function manageAction() { $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm'); $render['#form'] = $form; $render['#theme']$render['theme'] = 'manage_cmodule_page'; return $render;; } 
$render['#theme']$render['theme'] = 'manage_atps_page'; 

the page loads, but it is empty (without any form).

UPDATE #2

I fixed my issue following also the idea of Alex Kuzava. Thus I used the code of UPDATE 1, with the new directory of the form, and then I added these 3 lines inside the part of my template (otherwise the submit button doesn't work).

{{ form.form.form_build_id }} {{ form.form.form_id }} {{ form.form.form_token }} 
controller contains: public function manageAction() { $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm'); $render['#form'] = $form; $render['#theme'] = 'manage_cmodule_page'; return $render;; } 
$render['#theme'] = 'manage_atps_page'; 

the page loads, but it is empty (without any form).

controller contains: public function manageAction() { $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm'); $render['#form'] = $form; $render['theme'] = 'manage_cmodule_page'; return $render;; } 
$render['theme'] = 'manage_atps_page'; 

the page loads, but it is empty (without any form).

UPDATE #2

I fixed my issue following also the idea of Alex Kuzava. Thus I used the code of UPDATE 1, with the new directory of the form, and then I added these 3 lines inside the part of my template (otherwise the submit button doesn't work).

{{ form.form.form_build_id }} {{ form.form.form_id }} {{ form.form.form_token }} 
added 35 characters in body
Source Link
que le
  • 71
  • 2
  • 2
  • 8

UPDATE #1 I tried also to follow the suggestion of Beebee, and then this and this so the code is:

UPDATE #1 I tried also to follow this and this so the code is:

UPDATE #1 I tried also to follow the suggestion of Beebee, and then this and this so the code is:

UPDATE #1
Source Link
que le
  • 71
  • 2
  • 2
  • 8

cmodule.routing.yml: cmodule.routing.yml:

RequestForm.php: RequestForm.php:

/** * {@inheritdoc} * */ public function buildForm(array $form, FormStateInterface $form_state) {   $form['type'] = [array( '#type'  '#type' => 'radios',   '#options' => [array( '0' => t '0' =>t('DOC'), '1' => t '1' =>t('PDF'), ] ), ];  );   $form['pid'] = [array( '#type' '#type' => 'textfield', '#title'  '#title' => t('ID:'),   '#required' => FALSE, ];  );   $form['submit'] = [array(   '#type'  '#type' => 'submit', '#value'  '#value' => $this->t('Submit'), '#attributes' => ['class' => ['glyphicon''#attributes'=> ['class'=>['glyphicon', 'glyphicon-search']], ]; );    return $form; } 

cmodule.module: cmodule.module:

/** * Implements hook_theme(). */ function atps_themecmodule_theme() {   $templates = [array(   'manage_cmodule_page' => [array( 'variables'  'variables' =>   [ 'id'  'id' => NULL,   'form' => NULL,   ],   'template' =>'template' 'manage_cmodule'=>'manage_cmodule',   'render element' => 'form', ], ) ]; );   return $templates; } 

the controller contains: the controller contains:

public function manageAction() {     $id = 1;   $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm');   $form['type']['#title_display'] = 'invisible'; return [   return [ '#theme' => 'manage_cmodule_page', '#form'  '#form' => $form, '#id'  '#id' => $id,   ];  } 

and then the template/view (contains): and then the template/view (contains):

<div> {{ form.form_token }} {{ form.typeform_build_id }} {{ form.form_id }}   {{form.type}} {{form.submit}} </div> etc.. 

But as I said above the template doesn't show the form, but show (if i print it) the #id value passed through the controller. Do you have any suggestions?!


UPDATE #1 I tried also to follow this and this so the code is:

controller:

controller contains: public function manageAction() { $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm'); $render['#form'] = $form; $render['#theme'] = 'manage_cmodule_page'; return $render;; } 

and the implementation of hook_theme in .module file is:

return [ 'manage_cmodule_page' => [ 'template' =>'manage_cmodule', 'render element' => 'form', ] ]; 

The result is an empty page with an error inside the apache log:

[php7:error] [pid 12660:tid 1592] [client ::1:59521] PHP Fatal error: Out of memory (allocated 270532608) (tried to allocate 266354688 bytes) in C:\drupal\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 60, referer: http://localhost/drupal/

if I remove the following row from the controller

$render['#theme'] = 'manage_atps_page'; 

the page loads, but it is empty (without any form).

cmodule.routing.yml:

RequestForm.php:

/** * {@inheritdoc} * */ public function buildForm(array $form, FormStateInterface $form_state) { $form['type'] = [ '#type' => 'radios', '#options' => [ '0' => t('DOC'), '1' => t('PDF'), ], ];  $form['pid'] = [ '#type' => 'textfield', '#title' => t('ID:'), '#required' => FALSE, ];  $form['submit'] = [   '#type'  => 'submit', '#value'  => $this->t('Submit'), '#attributes' => ['class' => ['glyphicon', 'glyphicon-search']], ]; return $form; } 

cmodule.module:

/** * Implements hook_theme(). */ function atps_theme() { $templates = [ 'manage_cmodule_page' => [ 'variables' => [ 'id' => NULL, 'form' => NULL, ],   'template' => 'manage_cmodule', 'render element' => 'form', ], ]; return $templates; } 

the controller contains:

public function manageAction() { $id = 1; $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm'); $form['type']['#title_display'] = 'invisible'; return [  '#theme' => 'manage_cmodule_page', '#form' => $form, '#id' => $id, ]; } 

and then the template/view (contains):

<div> {{form.type}} {{form.submit}} </div> etc.. 

But as I said above the template doesn't show the form, but show (if i print it) the #id value passed through the controller. Do you have any suggestions?!

cmodule.routing.yml:

RequestForm.php:

/** * {@inheritdoc} * */ public function buildForm(array $form, FormStateInterface $form_state) {   $form['type'] = array(   '#type' => 'radios',   '#options' => array(  '0' =>t('DOC'),  '1' =>t('PDF')  ),  );   $form['pid'] = array( '#type' => 'textfield',   '#title' => t('ID:'),   '#required' => FALSE );   $form['submit'] = array( '#type' => 'submit', '#value' => $this->t('Submit'), '#attributes'=> ['class'=>['glyphicon', 'glyphicon-search']],  );    return $form; } 

cmodule.module:

/** * Implements hook_theme(). */ function cmodule_theme(){   $templates = array(   'manage_cmodule_page' => array(   'variables' =>   [   'id' => NULL,   'form' => NULL   ], 'template' =>'manage_cmodule',   'render element' => 'form'  )  );   return $templates; } 

the controller contains:

public function manageAction() {     $id = 1;   $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm');   $form['type']['#title_display'] = 'invisible';   return [ '#theme' => 'manage_cmodule_page',   '#form' => $form,   '#id' => $id,   ];  } 

and then the template/view (contains):

<div> {{ form.form_token }} {{ form.form_build_id }} {{ form.form_id }}   {{form.type}} {{form.submit}} </div> etc.. 

But as I said above the template doesn't show the form, but show (if i print it) the #id value passed through the controller. Do you have any suggestions?!


UPDATE #1 I tried also to follow this and this so the code is:

controller:

controller contains: public function manageAction() { $form = \Drupal::formBuilder()->getForm('Drupal\cmodule\Forms\RequestForm'); $render['#form'] = $form; $render['#theme'] = 'manage_cmodule_page'; return $render;; } 

and the implementation of hook_theme in .module file is:

return [ 'manage_cmodule_page' => [ 'template' =>'manage_cmodule', 'render element' => 'form', ] ]; 

The result is an empty page with an error inside the apache log:

[php7:error] [pid 12660:tid 1592] [client ::1:59521] PHP Fatal error: Out of memory (allocated 270532608) (tried to allocate 266354688 bytes) in C:\drupal\vendor\twig\twig\lib\Twig\Extension\Debug.php on line 60, referer: http://localhost/drupal/

if I remove the following row from the controller

$render['#theme'] = 'manage_atps_page'; 

the page loads, but it is empty (without any form).

coding standards
Source Link
norman.lol
  • 19.1k
  • 6
  • 75
  • 129
Loading
edited title
Link
norman.lol
  • 19.1k
  • 6
  • 75
  • 129
Loading
added 3 characters in body
Source Link
que le
  • 71
  • 2
  • 2
  • 8
Loading
added 128 characters in body
Source Link
que le
  • 71
  • 2
  • 2
  • 8
Loading
added 245 characters in body
Source Link
que le
  • 71
  • 2
  • 2
  • 8
Loading
Source Link
que le
  • 71
  • 2
  • 2
  • 8
Loading