Click here to Skip to main content
15,611,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had already asked for help to resolve this issue. But I have got an advise to describe my issue in more details for increasing chances to get an answer. And I will try to do it. I have a checkout page in my website. There are 3 payment methods (Bank transfer, PayPal, Hello).(please see the image_checkout1). "Hello" is the payment method added by myself. I need to stylize using CSS, Hello payment method. I found in the Dev. dashboard html code which creates these payment methods in a browser.(please see the image_checkout2). After that I found php file, below is code which dynamically creates these label tags(if I understand this process correctly).

//13.getRadioPaymode
 function getRadioPaymode($var, $default, $disabled, $type){
   $app = JFactory::getApplication();
   $db  = JFactory::getDbo();
   $html = '';
   $gatewayType = 'TRUE';
   $i = 0;

   $option = '';
   if($disabled == 1)
     $option = 'disabled';

   if($type == 'deposit')
     $gatewayType = 'is_deposit=1';
   if($type == 'subscription')
     $gatewayType = 'is_subscription=1';

   $query = "SELECT gwcode AS value, gateway_name AS text FROM #__jblance_paymode ".
        "WHERE published=1 AND ".$gatewayType." ".
        "ORDER BY ordering";
   $db->setQuery($query);
   $paymodes = $db->loadObjectList();

   if(empty($paymodes)){
     $html = '<p class="alert alert-error">'.JText::_('COM_JBLANCE_NO_PAYMENT_GATEWAY_ENABLED').'</p>';
     return $html;
   }

   foreach($paymodes as $item){
     $checked = $img = '';
     $imgPath = "components/com_jblance/gateways/images/$item->value.png";

     //keep the first element checked
     if(++$i == 1) $checked="checked";

     if(JFile::exists($imgPath))
       $img = '<img class="img-polaroid" title="" src="'.$imgPath.'" alt="'.$item->text.'" style="margin-left:10px; width:100px; height:30px;">';


 $html .=  "\n\t".
           '<label class="radio"  style="min-height:42px;">'. "\n".
           '<input type="radio" style="float:none;" name="'.$var.'" id="'.$var.'" value="'.$item->value.'" '.$checked.'>'.
           $img.
           '<span style="margin-left: 10px;">'.JText::_($item->text).'</span>'.
           '</label>';


    }


  $html .= "\n";
   return $html;


   }


Below is a part of code of php file which is rendering the page with the issue. And in this code is function which added above.

<div class="sp10"</div>
    <div id="div-gateway" class="well well-small white">
      <div class="control-group">
        <label class="control-label" for="delivery"><?php echo JText::_('COM_JBLANCE_PAYMENT'); ?>:</label>
        <div class="controls">
          <?php 
          $list_paymode = $model->getRadioPaymode('gateway', '', '', 'subscription');
          echo $list_paymode;
          var_dump($list_paymode);
          ?>
        </div>
      </div>
    </div>


What I have tried:

After that as I asked for help on this site in the first time. I have got a solution. I have inserted a code from this solution. This is my code after adding the code from the solution

$idlist = array("ida", "idb", "idc");
     foreach($idlist as $id){
     $html .=  "\n\t".

          '<label id="' . $id . '" class="radio" style="min-height:42px;">'. "\n".

           '<input type="radio" style="float:none;" name="'.$var.'" id="'.$var.'" value="'.$item->value.'" '.$checked.'>'.
           $img.
           '<span style="margin-left: 10px;">'.JText::_($item->text).'</span>'.

             '</label>';

     }

   }

   $html .= "\n";
   return $html;


Ids were added into the label tags, but now I have 9 payment methods instead of 3 on the page (3 Bank transfer, 3 PayPal, 3 Hello)(please see the checkout_image3). I am new to php, I am just creating websites using CMS. Please help me to resolve this issue.
Posted
Updated 27-Aug-20 1:05am
v2
Comments
Patrice T 25-Aug-20 8:39am    
Member 14920672 25-Aug-20 8:50am    
Yes, a member asked me to explain my issue in more details and create a new question. This one "Dynamically generate elements with different ids" can be removed.
Patrice T 25-Aug-20 8:57am    
Use Improve question to update your question.
Richard MacCutchan 25-Aug-20 8:54am    
If you have ended up with nine objects instead of three then it sounds like you are repeating your variables too many times. that is not a coding problem, just simple logic. But the code above gives no clue as to what you are doing to get such a result.
Member 14920672 27-Aug-20 7:07am    
I added the full code of function and part of code which is rendering this function. Maybe it could help to find any solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900