Score:-2

How can i redirect to a separate page without filling value in the required field?

in flag

I have a site in drupal 9. I have one taxonomy with the name and and another field. I have a Go back button which takes me to a separate destination. The problem is that I cant click go back without giving some values in the name field as it is by default a required field in drupal. I want to click go back without giving anything in that name field. How can i achieve this?

Score:1
cn flag

You didn't post any code, but it sounds like your back button is somehow submitting the form (because it is validating the form, and failing required validation).

So the solution is to make sure the back button is not part of the form.

On my own site, to add a back button to some webforms, I add this HTML in a block that is shown on the webform page:

<button onClick="window.history.back()" class="button">Back</button>

You can easily do something similar with standard HTML + JS.

Score:1
de flag

Another option if you cannot move the back button out of the form (and if it uses the Form API), would be to use the #limit_validation_errors property to avoid any form validation.

The example below can be used if you are building the form by yourself. If using a hook_form_alter(), just add the #limit_validation_errors line.

$form['back'] = [
  '#type' => 'submit',
  '#value' => $this->t('Back'),
  '#submit' => ['::yourSubmitCallback'],
  '#limit_validation_errors' => [], // This will ensure any validation is skipped
];
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.