<?php
/**
* ChronoForms 8
* Copyright (c) 2023 ChronoEngine.com, All rights reserved.
* Author: (ChronoEngine.com Team)
* license:     GNU General Public License version 2 or later; see LICENSE.txt
* Visit http://www.ChronoEngine.com for regular updates and information.
**/
defined('_JEXEC') or die('Restricted access');
?>
<?php
	if(str_contains($element["code"], "{fields:completed}")){
		$table = '<table>';
		foreach($completed_elements as $complete){
			// Chrono::pr($complete);
			if(str_starts_with($complete["name"], "field_") && $complete["name"] != "field_button"){
				$fname = CF8::cleanfieldname($complete["fieldname"]);
				$fname = CF8::parse($fname);
				$field_value = implode("<br>", (array)$this->data($fname, ""));
				if(in_array($complete["name"], ["field_checkboxes", "field_radios", "field_select"])){
					$field_value = implode("<br>", (array)$this->get($fname.".selection", []));
				}
				$label = CF8::getlabel($complete);
				$table .= '<tr>
					<td style="vertical-align:top;"><strong>'.$label.'</strong></td>
					<td>'.$field_value.'</td>
				</tr>';
			}
		}
		$table .= '</table>';
		$element["code"] = str_replace("{fields:completed}", $table, $element["code"]);
	}
	
	echo $element["code"];