user3361761
user3361761

Reputation: 259

Passing a template variable as input to a hidden form input field

I have a template index.html which contains a table of data. At the end of each row data, there is an edit button which allows you to edit the column entries in that row.

Here is how my table is constructed in index.html:

<table style="width:300px">
            <tr>
                <td> Mailing List Name</td>
                <td> Mailing List Creation Date</td>
            </tr>

            {% for listEntry in lists %}
                <tr>
                    <td>{{ listEntry.name }}</td>
                    <td>{{ listEntry.create_date }}</td>
                    <td>
                        <form action="/list_edit" method="post">
                            <input id="submit" type="submit" value="Edit" />
                            **Extra hidden input fields would be added here**
                        </form>
                    </td>
                </tr>
            {%endfor%}

        </table>

How can I pass variables defined in the ListEntry model as hidden input fields to a form?

Upvotes: 0

Views: 1725

Answers (1)

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83788

Try:

  <input name="{{ listEntry.someId }}" type="hidden" value="{{ listEntry.value }}" />

However if you have one <form> element per row, you need to give submit action a value based on which row it is too.

Upvotes: 1

Related Questions