New answers tagged forms
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.
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',
'#...
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, '...
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 &&...
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;...
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
...
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' =...
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 {
...
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 ...
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"
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'),
...
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.
Top 50 recent answers are included
Related Tags
forms × 68307 × 2093
8 × 1391
ajax × 1012
theming × 536
users × 401
nodes × 396
webforms × 302
javascript × 282
hooks × 282
views × 241
entities × 233
files × 208
6 × 194
9 × 143
blocks × 139
commerce × 120
emails × 95
taxonomy-terms × 94
routes × 92
redirection × 90
database × 89
media × 88
comments × 73
datetime × 69