1

I am absolutely new to HTML and I was wondering if Someone could help me out. I tried looking for similar questions as mine but I didn't find anything quite like what I am looking for. Sorry if this question seems dumb or easy to you I am trying to learn! So basically I have an ID that I can access inside of my HTML file and I want to send it to my python function through a form, I have already managed to do this for buttons but never for a form. This is how I would send my ID to my function with a button:

<a href="{{url_for('validate_comment', item_id=msr.id)}}"> <--- the msr.id is my ID
    <button type="button">
        <div class="font-weight-bold">Ajouter un commentaire</div>
    </button>
</a>

And this works perfectly but i was wondering if there was any way to do the same with a form as I am not calling a function but doing an action instead. This is how my form looks:

<form id="commentaire_form" method="post" action="/testement"> <--- here is where I give the route but how can i send the ID to the function linked to this route?
    <textarea id='text' name="text"></textarea>
    <input type="submit">
</form>

If anyone could help me I would greatly appreciate it, thanks in advance :-)

1 Answer 1

1

The below will make a POST request to the /testement route/URL. You can catch the id POST value in your python script.

<form id="commentaire_form" method="post" action="/testement">
    <textarea id='text' name="text"></textarea>
    <input type="hidden" name="id" value="{{ msr.id }}">
    <input type="submit">
</form>
Sign up to request clarification or add additional context in comments.

2 Comments

oh wow I didn't know you could do it like that, what a great idea! Thank you very much I will try it right now!
I was able to catch the id just like you said, thank you very much this helps me a lot! Congratulations on the 1000 reputation by the way!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.