0

I need to get values from input form of tera template to rocket code. How can I do that? Here is the template:

{% extends "base" %}

{% block content %}
    <h3>Task:</h3>
    <ul>
        <p>{{task}}</p>
        <input type="text" name="answer">
    </ul>

    <p>Return to main menu <a href="/home">Home</a></p>
{% endblock content %}

I need somehow retrieve the value from the field. If there is a way to receive it by pressing "Enter" that would be even nicer. Thank you for your attention.

I know what to do on the rocket end, but I don't know how to send data from tera templates.

Also, if somebody can say how to do it by pressing "Enter" for example, that would be really great.

vallentin
  • 23,478
  • 6
  • 59
  • 81
  • You can just use an HTML form. – Ibraheem Ahmed Jan 22 '21 at 16:42
  • @IbraheemAhmed It is just an example, templates are allowing more flexibility, and I want to know how to use it. Although I don't know how to do it with simple HTML, I need to know how to do it with tera templates. – Mikhail Gavrilec Jan 22 '21 at 16:44
  • Tera is just a tool that allows you to use variables and functions in HTML. In the end, it just outputs regular HTML. You should probably [learn how to use html forms](https://www.w3schools.com/html/html_forms.asp) first. Then, you can capture the HTML data with [rocket form guards](https://rocket.rs/v0.4/guide/requests/#forms). – Ibraheem Ahmed Jan 22 '21 at 17:36
  • 1
    @IbraheemAhmed Yeah, you are right, it is a simple html form, and I can treat it as an ordinary submitting form. Thank you for help. – Mikhail Gavrilec Jan 22 '21 at 19:44

0 Answers0