Skip to main content
removed "Drupal" from the title; removed tags from the title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Drupal 8, how How do I programmatically disable a form programmatically?

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( II mean : removeremoving all fields form). I think I can unset all form elements, but I feel that is an ugly way ;).

Is there a method (from the FormStateInterface class) or a drupalDrupal function (for the form variable) for disableto properly disable the form  ?

Thank you !

My last try :This is my most recent tentative.

function mycustommodule_limit_form_user_register_form_alter(&$form, FormStateInterface $form_state){
  if (...) {
    $form['#access'] = FALSE; // Drupal 7 (ugly?) way
    drupal_set_message('This form is disable because...');
  }
}

When I go to the /user/register form, the form is disable ! but I get this drupal error

"Notice: Undefined index: #markup in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 323 of core/lib/Drupal/Core/Render/RenderCache.php)." :

enter image description here

Notice: Undefined index: #markup in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 323 of core/lib/Drupal/Core/Render/RenderCache.php).

screenshot

And I would like to hide/remove the 'Create new account' title.Create new account too.

Drupal 8, how disable a form programmatically?

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( I mean : remove all fields form). I think I can unset all form elements, but I feel that is an ugly way ;)

Is there a method (from the FormStateInterface class) or a drupal function (for the form variable) for disable properly the form  ?

Thank you !

My last try :

function mycustommodule_limit_form_user_register_form_alter(&$form, FormStateInterface $form_state){
  if (...) {
    $form['#access'] = FALSE; //Drupal 7 (ugly?) way
    drupal_set_message('This form is disable because...');
  }
}

When I go to the /user/register form, the form is disable ! but I get this drupal error

"Notice: Undefined index: #markup in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 323 of core/lib/Drupal/Core/Render/RenderCache.php)." :

enter image description here

And I would like hide/remove the 'Create new account' title..

How do I programmatically disable a form?

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically (I mean removing all fields form). I think I can unset all form elements, but I feel that is an ugly way.

Is there a method (from the FormStateInterface class) or a Drupal function (for the form variable) to properly disable the form?

This is my most recent tentative.

function mycustommodule_limit_form_user_register_form_alter(&$form, FormStateInterface $form_state){
  if (...) {
    $form['#access'] = FALSE; // Drupal 7 (ugly?) way
    drupal_set_message('This form is disable because...');
  }
}

When I go to the /user/register form, the form is disable ! but I get this error.

Notice: Undefined index: #markup in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 323 of core/lib/Drupal/Core/Render/RenderCache.php).

screenshot

I would like to hide/remove Create new account too.

added 689 characters in body
Source Link
spacecodeur
  • 1.3k
  • 3
  • 32
  • 55

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( I mean : remove all fields form). I think I can unset all form elements, but I feel that is an ugly way ;)

Is there a method (from the FormStateInterface class) or a drupal function (for the form variable) for disable properly the form ?

Thank you !

My last try :

function mycustommodule_limit_form_user_register_form_alter(&$form, FormStateInterface $form_state){
  if (...) {
    $form['#access'] = FALSE; //Drupal 7 (ugly?) way
    drupal_set_message('This form is disable because...');
  }
}

When I go to the /user/register form, the form is disable ! but I get this drupal error

"Notice: Undefined index: #markup in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 323 of core/lib/Drupal/Core/Render/RenderCache.php)." :

enter image description here

And I would like hide/remove the 'Create new account' title..

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( I mean : remove all fields form). I think I can unset all form elements, but I feel that is an ugly way ;)

Is there a method (from the FormStateInterface class) or a drupal function (for the form variable) for disable properly the form ?

Thank you !

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( I mean : remove all fields form). I think I can unset all form elements, but I feel that is an ugly way ;)

Is there a method (from the FormStateInterface class) or a drupal function (for the form variable) for disable properly the form ?

Thank you !

My last try :

function mycustommodule_limit_form_user_register_form_alter(&$form, FormStateInterface $form_state){
  if (...) {
    $form['#access'] = FALSE; //Drupal 7 (ugly?) way
    drupal_set_message('This form is disable because...');
  }
}

When I go to the /user/register form, the form is disable ! but I get this drupal error

"Notice: Undefined index: #markup in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 323 of core/lib/Drupal/Core/Render/RenderCache.php)." :

enter image description here

And I would like hide/remove the 'Create new account' title..

Source Link
spacecodeur
  • 1.3k
  • 3
  • 32
  • 55

Drupal 8, how disable a form programmatically?

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( I mean : remove all fields form). I think I can unset all form elements, but I feel that is an ugly way ;)

Is there a method (from the FormStateInterface class) or a drupal function (for the form variable) for disable properly the form ?

Thank you !