#1 by dmartinezfelip
Hi all, I am programming a a public goods game where participants in the group have the opportunity to vote who is punished after oberving the contribution levels of their group members. When submitting the vote in the Results.html page there is an error in red in the experiment page saying: Pleae fix the errors. When checking the data generated while testing the code, no vote is submitted and no error message appears either in the python terminal or in the page console. Here is the html and javascript for the results.html page: {% extends "global/Page.html" %} {% block title %}Round Results{% endblock %} {% block content %} <h2>Results for Round {{ player.round_number }}</h2> <p>Your contribution: {{ player.contribution }}</p> <p>Total group contribution: {{ group.total_contribution }}</p> <p>Your share of the group contribution: {{ group.individual_share }}</p> <p>Your earnings this round: {{ player.payoff }}</p> <p>Your total payoff so far: {{ player.payoff }}</p> <h3>Contributions by Group Members</h3> <style> table { width: 100%; border-collapse: collapse; margin: 20px 0; } th, td { border: 1px solid #ddd; padding: 8px; text-align: center; } th { background-color: #04AA6D; color: white; } tr:nth-child(even) { background-color: #f2f2f2; } tr:hover { background-color: #ddd; } </style> <table> <tr> <th>Players ID in this round</th> <th>Contribution (% of Endowment)</th> </tr> {% for p in player.group.get_players() %} <tr> <td>Player {{ p.random_id }}</td> <td>{{ p.contribution_percentage }}%</td> </tr> {% endfor %} </table> <h3>Vote for a Player</h3> <form method="post"> {% for id, label in players %} <!-- Assign an unique ID to each input --> <input type="radio" id="vote_for_{{ id }}" name="vote_for_player" value="{{ id }}"> <!-- Reference the input's ID in the label's for attribute --> <label for="vote_for_{{ id }}"> {{ label }} </label><br> {% endfor %} <button type="submit" class="btn btn-primary">Submit Vote</button> </form> {% endblock %} And this the python code linked to it: class Player(BasePlayer): vote_for_player = models.StringField( widget = widgets.RadioSelectHorizontal, choices = [], blank = False # Mandatory voting ) def get_vote_choices(player): # Include 'No Vote' option at the beginning of the choices list choices = [("0", "No Vote")] choices.extend([(str(p.id_in_group), f"Player {p.random_id}") for p in player.get_others_in_group()]) return choices class Results(Page): form_model = 'player' form_fields = ['vote_for_player'] def vars_for_template(player): # Provide a list of players to the template, excluding the current player return { 'players': player.get_vote_choices() } @staticmethod def before_next_page(player, timeout_happened): # Print statement to check if the method is called print(f'before_next_page called for player {player.id_in_group}') # Print the value of vote_for_player print(f'Player {player.id_in_group} voted for: {player.vote_for_player}') If anyone has any idea of how I can solve this problem i would be very grateful. Thank you very much. Daniel
#2 by Chris_oTree
You're not supposed to put a <form> element on the page. That is handled by oTree automatically.
#3 by dmartinezfelip
Hi Chris, thanks for your help and suggestion. I have tried it eliminating the </form> element but the error persists. I have the </form> element in my contriution.html page as well and is not causing any problems. Daniel