Forums

Custom Code inside Multiplier container

jhaviro 21 Jun, 2017
Hello!!

I have a little question. I need to include inside a container "multiplier" a custom code but in doing so, it destroys the design. The code I need to include is:


<?php
$db =& JFactory::getDBO();
$count = $db->loadResult();

$query = "
SELECT DISTINCT `cd_servicio`, `cd_idioma_origen`, `cd_idioma_destino`
FROM `j4tyn_z_tservicios_real` ORDER BY `cd_idioma_origen`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
?>
<div class="form-group gcore-form-row" id="form-row-cd_servicio1"><label for="cd_servicio1" class="control-label gcore-label-left">Servicio</label>
<div class="gcore-input gcore-display-table" id="fin-cd_servicio1"><select name="Data[__N__][cd_servicio]" id="cd_servicio__N__" size="0" class="form-control A" title="" style="" data-load-state="" data-tooltip="">
<option value="">-- Seleccionar un Servicio --</option>

<?php
$optgroup = '';
foreach ( $data as $d ) {
$selected = '';
if ( $d->id == cd_servicio ) {
$selected = "selected='selected'";
}
if ( $d->cd_idioma_origen != $optgroup ) {
if ( $optgroup ) {
echo "</optgroup>";
}
echo "<optgroup label='{$d->cd_idioma_origen}'>";
$optgroup = $d->cd_idioma_origen;
}
echo "<option value='{$d->cd_servicio}' $selected >{$d->cd_idioma_destino} - Cod: {$d->cd_servicio}</option>";
}
echo "</optgroup>";
?>
</select>
</div></div>


The code works perfectly, is based on this POST
Trying to place the custom code destroys the layout of the form. Can I do it any other way?

Thanks for the help!! Cordially
Javierp.
GreyHead 22 Jun, 2017
Hi Javierp,

I'm not sure that this will work at all. The Multiplier adds a copy of some HTML in the browser using JavaScript - the PHP you have here is run on the server before the page is created. You can possibly run the PHP in a Custom Code action before the HTML (Render form) action, add the generated HTML to the $form->data array and then include the result in the multiplier.

Bob
jhaviro 22 Jun, 2017
Good afternoon.

Yes, I'm going to try, although tweaking the design I have managed to leave everything "almost fine". The problem is that, when I place the "custom code", the styles where I apply percentages no longer work ... However, I will try to do as you advise.

Thank you very much.
Javierp
This topic is locked and no more replies can be posted.