Developing a form using custom module for members to update football match day statistics. These include team sheets, goals substitutions. I have been able to get the team sheets working grand but stuck on adding in the goal scorers. On my form I will have to have a row per goal, so if a team scores 1,2,X amount of goals in the game I will need the same amount of rows. The data to be saved will be player, time of goal and whether a penalty or not.
I have a drop down list for the players name, textbox for time and a checkbox for penalty.
What I need help with is how to display the number of rows per goal. And I would also like use the same form for adding and editing the goals.
My module function
public function match_stats(){
$match_id = ee()->TMPL->fetch_param('match_id');
$team_id = ee()->TMPL->fetch_param('team_id');
$match = ee()->clubmanager_matches->__get_match($match_id);
$sql = "SELECT club_id FROM exp_ca_exec_clubs where member_id = ?";
$query = ee()->db->query($sql, array(ee()->session->userdata('member_id')));
$club_id = $query->row()->club_id;
$season_id = 16;
// Build an array to hold the form's hidden fields
$hidden_fields = array(
"match_id" => $match_id,
"club_id" => $club_id,
"team_id" => $team_id,
"season_id" => $season_id,
"ACT" => ee()->functions->fetch_action_id( 'Clubmanager', 'match_team_action' ),
"return" => ee()->TMPL->fetch_param('return')
);
// Build an array with the form data
$form_data = array(
// Send form back to this url - the action must be the same as the form
"action" => ee()->functions->create_url( ee()->uri->uri_string ),
"id" => ee()->TMPL->form_id,
"class" => 'form-horizontal',
"hidden_fields" => $hidden_fields
);
// Make sure errors is actually an array
if( ! is_array( self::$errors ) ) {
self::$errors = array();
}
// Match Stats Goals
$matchPlayersList = ee()->clubmanager_players->__get_match_players_list($team_id, $match_id);
$clubplayerslist = ee()->clubmanager_players->__get_club_players_list($club_id, $season_id);
if($matchPlayersList > 0):
$variables['players'] = $matchPlayersList;
else:
$variables['players'] = $clubplayerslist;
endif;
// Set up array to parse tagdata
$variables['errors'] = array(
array( self::$errors )// list of error messages
);
// Fetch contents of the tag pair, ie, the form contents
$tagdata = ee()->TMPL->tagdata;
// Parse tagdata for errors/submitted values
$tagdata = ee()->TMPL->parse_variables_row( $tagdata, $variables );
// Create the form
$form = ee()->functions->form_declaration($form_data) .
$tagdata .
"</form>";
return $form;
}
My template code
{exp:clubmanager:match_stats
match_id="{segment_3}"
team_id="{segment_4}"
return="clubhouse/fixtures/edit-success"
}
<!--Table Search v1-->
<div class="table-search-v1 margin-bottom-20">
<div class="table-responsive">
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>Player Name</th>
<th>Assist Player Name</th>
<th>Goal Time</th>
<th>Penalty</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select name="player_goal">
<option value="0">Select Player</option>
{players}
<option value="{id}">{name}</option>
{/players}
</select>
</td>
<td>
<select name="player_assist">
<option value="0">Select Player</option>
{players}
<option value="{id}">{name}</option>
{/players}
</select>
</td>
<!-- Text input-->
<td>
<input type="text" placeholder="time" class="form-control" name="time" value="{time}" />
</td>
<td>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!--End Table Search v1-->