Search code examples
springspring-bootthymeleafspring-thymeleaf

How to submit a hidden string in a form with Spring Boot and Thymeleaf?


I want to send a string from an HTML form to a Spring Boot controller but I would like this string not to be visible to the client. I would like to use the hidden field but something is not working and I don't understand where I'm wrong. In the code you will find all my proofs.

    <form th:action="@{/test-server-asincrono}" th:object="${InterrompiAsincrono}" method="POST">
    <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">
    <!--/*<input type="hidden" th:field="*{interrompi}" id="interrompi" th:value="si">*/-->
    <!--/*<input type="hidden" th:field="*{interrompi}" id="interrompi" value="${'si'}">*/-->
    <!--/*<input type="hidden" th:field="*{interrompi}" id="interrompi" value="si">*/-->
    <!--/*<input type="hidden" th:name="*{interrompi}" id="interrompi" value="si">*/-->
    <select th:field="*{interrompi}" class="form-select">
        <option th:value="si">Si</option>
    </select>
    <input type="submit" value="Interrompi il test" class="btn btn-primary">
    </form>

Solution

  • <input type="hidden" name="interrompi" value="si">