New answers tagged

0 votes

How can I compare date time values in a content form?

\DateTime objects are directly comparable without having to resolve them to scalar values.
cilefen's user avatar
  • 5,557
0 votes

How to add a reset button to forms?

I was able to get this to work. Within the buildForm() method, part of the form array contains this for the reset button: $form['rmdrs_form_reset_button'] = array( '#type' => 'submit', '#...
Cy Jobes's user avatar
0 votes

Form with two submission buttons

#submit: Specifies an alternate callback for form submission when the submit button is pressed. Use '::methodName' format or an array containing the object and method name (for example, [ $this, '...
Kedar Khaire's user avatar
1 vote

How can I compare date time values in a content form?

Instead of a string and strtotime() you could get the timestamp directly via the method getTimeStamp(): use Drupal\Core\Datetime\DrupalDateTime; ... if ($start_time instanceof DrupalDateTime &&...
4uk4's user avatar
  • 98.1k
0 votes

How to change the title and add a placeholder to password and confirm password field through hook_form_alter?

Code to Alter pass & confirm pass field title along with password strength indicator display: Drupal(8/9/10) use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\PasswordConfirm;...
mini's user avatar
  • 682
1 vote

Make a custom action with form

In above code this "system.action.test_action.yml" file missing : add this file inside this folder: module/config/optional, only then custom action 'll start appear under action select list ...
mini's user avatar
  • 682
0 votes

How do I prevent a form from being cached for anonymous users?

In order to prevent a form from caching at all, you can include the following #cache key in your form along with max-age & context attributes: $form['#cache'] = [ 'max-age' => 0, 'contexts' =...
mini's user avatar
  • 682
0 votes

How to set widget for a field on a custom form?

I encountered a similar challenge, and after some experimentation, I found a solution that works well for my specific case. public function blockForm($form, FormStateInterface $form_state): array { ...
edykst's user avatar
  • 1
0 votes

missing form tag while embedding and stylizing form elements

You have to nest multiple templates, you can't solve this in a single template. See for example the standard node edit form which is rendered as main content in a block, this block renders the form ...
4uk4's user avatar
  • 98.1k
0 votes

Prepopulating a drop-down select box that references another entity

Just realized I needed to query the ID and not the actual value. Like "https://.../node/add/space?floor=1" or "https://.../node/add/space?floor=floor 2"
BMM's user avatar
  • 103
0 votes

How to use 'required' and 'optional' states with form api when using a select field?

You have to tweak code like this: $form['field_2'] = [ '#type' => 'select', '#title' => $this->t('Field 2'), '#options' => [ 'A' => $this->t('A'), ...
mini's user avatar
  • 682
0 votes
Accepted

Why is my message not showing for anonymous user?

It was drupal_flush_all_caches() that was the reason of message not showing. Once removed, everything works as expected.
gbmapo's user avatar
  • 1,066

Top 50 recent answers are included