- 🇩🇪Germany ammaletu Bonn, Germany
The two lines in #3 indeed fix this issue -- but they also potentially open up a new, horrible bug! We added these lines, and now when more than one guest user opens a page with this form, only one of them can submit the form (whoever is quickest). The rest get a "Integrity constraint violation, duplicate entry for node_field__uuid__value" error. This only happens for guest users, because for them the whole page is cached. As I said, a horrible bug for end-users and hard to spot when testing alone.
Think very hard before simply adding these two lines. Are these forms which are displayed to guest users and do you have the static page cache enabled? Not caching the form and using a unique form ID might be the better solution. We will for now try to simply not cache pages which have these forms. Together with the cache kill switch, the fix from #3 seems to work.
- 🇮🇳India sukr_s
The issue it seems that the block loads the configuration for the first block found and therefore the arguments of the first form are used. However if you check the user input in $form_state, the values sent from the browser are correct. I'm assuming that the arguments are stored in hidden fields. If so, you can check for user input for these values and use them if found, otherwise use from arguments
e.g.public function buildForm(array $form, FormStateInterface $form_state, $id) { $input_values = $form_state->getUserInput(); $form['id_value'] = [ '#type' => 'hidden', '#value' => isset($input_values['id_value'])? $input_values['id_value'] : $id, ]; $form['txt'] = [ '#type' => 'textfield', '#title' => 'Textfield', '#default_value' => $id, '#required' => TRUE, ]; $form['submit'] = [ '#type' => 'submit', '#value' => 'Submit' ]; return $form; }
with this approach the submit and validate have the correct values for the argument fields.