I have built an OpenCart module and tested it on a few shops and it works well. One client just reported to me a problem and after inspecting the html I saw this:
My code in the .tpl template file:
<table class="table table-bordered table-hover" >
<tbody>
<?php foreach($row['strings'] as $row_string){
$key = $row_string['key'];
$id = $row['simpleFilePathEscaped'].$key; ?>
<tr>
<td class="text-center">
<label><?php echo $key; ?> </label>
</td>
<td class="text-center">
<div>
<input id="text_value_<?php echo $id; ?>" type="text" value="<?php echo $row_string['value']; ?>" placeholder="<?php echo $key; ?>" class="form-control" />
</div>
</td>
<td class="text-center" >
<button id="save_icon_<?php echo $id; ?>" onclick="addLiteralToFile('<?php echo $row['secondary_file_path_escaped'] ?>', '<?php echo $key; ?>', '<?php echo $id;?>');" class="btn btn-primary"><i id="save_inner_icon_<?php echo $id; ?>" class="fa fa-save"></i></button>
<div id="loading_icon_<?php echo $id; ?>" <div class="loader"></div> </div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
The result for an example row in this client's shop is this:
<tr>
<td class="text-center" >
<label>direction</label>
</td>
<td class="text-center">
<div>
<input id="text_value_" type="text" value="ltr" placeholder="direction" class="form-control">
</div>
</td>
<td class="text-center">
<button id="save_icon_" onclick="addLiteralToFile('----home----admin----domains----itrend.si----public_html----test----admin----language----english----en-gb.php', 'direction', '');" class="btn btn-primary"><i id="save_inner_icon_" class="fa fa-save"></i></button>
<div id="loading_icon_" <div="" class="loader"></div>
</td>
</tr>
If you notice you will see that all instances of <?php echo $id; ?>
give an empty string. so id="save_icon_<?php echo $id; ?>"
becomes id="save_icon_"
That is extremely strange because $id
is a concat of $row['simpleFilePathEscaped']
and $key
. Even if $row['simpleFilePathEscaped']
is empty I know for sure that $key
has a value...Because it is echoed and in this example it is "direction" (in the label tag)
Need some help finding out why this is happening...
$row = { "strings" => array of { "key"=> string, "value"=> string },
"simpleFilePathEscaped" => string,
"secondary_file_path_escaped" => string,
"primary_file_path"=> string
}