Thread: PHP syntax help

Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2006
    Location
    Ohio
    Posts
    198
    Plugin Contributions
    0

    Default PHP syntax help

    I want to add a code to tpl_modules_attributes.php to display a popup link to explain the size (attribute) options. I got the popup to work, but I'd like to add an If/Then statment to only show when the options name is "Size." Pseudocod would be:

    if options_name = "Size"
    then display popup link (I got this part working)

    Thanks!
    Katie

  2. #2
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default Re: PHP syntax help

    try this:

    in tpl_modules_attributes.php, edit this line
    Code:
    <h4 class="optionName back"><?php echo $options_name[$i]; ?></h4>
    and change it to this (making sure the 'Size' matches your actual option name and putting your own code in the a href tag):
    Code:
    <h4 class="optionName back"><?php echo $options_name[$i] . ($options_name[$i] == 'Size' ? '<a href=....>?</a>' : ''); ?></h4>
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  3. #3
    Join Date
    Dec 2006
    Location
    Ohio
    Posts
    198
    Plugin Contributions
    0

    Default Re: PHP syntax help

    It didn't work. I think it's because I'm using a Javascript Popup:

    PHP Code:
    <a href="javascript:popupSizeHelp('http://www.ktnaturals.com/catalog/includes/extra_datafiles/sizehelp.html')"><img src="http://www.ktnaturals.com/catalog/includes/templates/custom/images/icons/help.gif" alt="Size Help"></a

  4. #4
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default Re: PHP syntax help

    Is the link and image code showing at all in the source code of your page? If not, then the conditional test $options_name[$i] == 'Size' is returning false
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  5. #5
    Join Date
    Dec 2006
    Location
    Ohio
    Posts
    198
    Plugin Contributions
    0

    Default Re: PHP syntax help

    Your code actually threw a syntax error.

    I thought the code would be

    PHP Code:
    <?php if ($options_name[$i] == 'Size') { ?>
    <a href="javascript:popupSizeHelp('http://www.ktnaturals.com/catalog/includes/extra_datafiles/sizehelp.html')"><img src="http://www.ktnaturals.com/catalog/includes/templates/custom/images/icons/help.gif" alt="Size Help"></a>
    <?php  ?>
    but it's returning False and not displaying the link. The link comes up as long as I don't have the If statement.

  6. #6
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default Re: PHP syntax help

    I just checked it on a freshly installed cart with demo data - the code I posted works correctly there.
    Can you post the entire section of tpl_modules_attributes.php that you edited?
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  7. #7
    Join Date
    Dec 2006
    Location
    Ohio
    Posts
    198
    Plugin Contributions
    0

    Default Re: PHP syntax help

    I need to mention that the line you were referring to, I commented out, because I thought it was redundant. But either way, I should be able to use the code you posted into line that says <?php echo TEXT_PRODUCT_OPTIONS; ?>, right? I want the link to appear before "Please choose:" like here:
    http://www.ktnaturals.com/catalog/in...products_id=34


    PHP Code:
    <?php
    /**
     * Module Template
     *
     * Template used to render attribute display/input fields
     *
     * @package templateSystem
     * @copyright Copyright 2003-2005 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_modules_attributes.php 3208 2006-03-19 16:48:57Z birdbrain $
     */
    ?>
    <div id="productAttributes">
    <?php if ($zv_display_select_option 0) { ?>
    <h5 id="attribsOptionsText">
    <!-- bof Popup Size Help 2/2k7/07 -->
    <a href="javascript:popupSizeHelp('http://www.ktnaturals.com/catalog/includes/extra_datafiles/sizehelp.html')"><img src="http://www.ktnaturals.com/catalog/includes/templates/custom/images/icons/help.gif" alt="Size Help"></a>
    <!-- eof Popup Size Help -->
    <?php echo TEXT_PRODUCT_OPTIONS?></h5>
    <?php // show please select unless all are readonly ?>
    <?php
        
    for($i=0;$i<sizeof($options_name);$i++) {
    ?>
    <?php
      
    if ($options_comment[$i] != '' and $options_comment_position[$i] == '0') {
    ?>
    <h4 class="attributesComments"><?php echo $options_comment[$i]; ?></h4>
    <?php
      
    }
    ?>
    <div class="wrapperAttribsOptions">
    <!-- <h4 class="optionName back"><?php echo $options_name[$i]; ?></h4> -->
    <center><?php echo "\n" $options_menu[$i]; ?></center>
    <br>
    </div>

    <?php if ($options_comment[$i] != '' and $options_comment_position[$i] == '1') { ?>
        <div class="ProductInfoComments"><?php echo $options_comment[$i]; ?></div>
    <?php ?>

    <?php
    if ($options_attributes_image[$i] != '') {
    ?>
    <?php 
    echo $options_attributes_image[$i]; ?>
    <?php
    }
    ?>
    <?php
        
    }
    ?>

    <?php
      
    if ($show_onetime_charges_description == 'true') {
    ?>
        <div class="wrapperAttribsOneTime"><?php echo TEXT_ONETIME_CHARGE_SYMBOL TEXT_ONETIME_CHARGE_DESCRIPTION?></div>
    <?php ?>

    <?php
      
    if ($show_attributes_qty_prices_description == 'true') {
    ?>
        <div class="wrapperAttribsQtyPrices"><?php echo zen_image(DIR_WS_TEMPLATE_ICONS 'icon_status_green.gif'TEXT_ATTRIBUTES_QTY_PRICE_HELP_LINK1010) . '&nbsp;' '<a href="javascript:popupWindowPrice(\'' zen_href_link(FILENAME_POPUP_ATTRIBUTES_QTY_PRICES'products_id=' $_GET['products_id'] . '&products_tax_class_id=' $products_tax_class_id) . '\')">' TEXT_ATTRIBUTES_QTY_PRICE_HELP_LINK '</a>'?></div>
    <?php ?>
    </div>

  8. #8
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default Re: PHP syntax help

    putting the code there is why your conditional test was returning false: the variable $i isn't set until the loop a few lines further down...
    You'll need to run the whole logic loop there to see if one of your options is size:

    try this:
    Code:
    <?php if ($zv_display_select_option > 0) { ?>
    <h5 id="attribsOptionsText">
    <?php
        for($i=0;$i<sizeof($options_name);$i++) {
           if ($options[$i] == 'Size') {
    ?>
     <!-- bof Popup Size Help 2/2k7/07 -->
    <a href="javascript:popupSizeHelp('http://www.ktnaturals.com/catalog/includes/extra_datafiles/sizehelp.html')"><img src="http://www.ktnaturals.com/catalog/includes/templates/custom/images/icons/help.gif" alt="Size Help"></a>
    <!-- eof Popup Size Help -->
    <?php 
        }
      }
    ?>
    <?php echo TEXT_PRODUCT_OPTIONS; ?></h5>
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  9. #9
    Join Date
    Dec 2006
    Location
    Ohio
    Posts
    198
    Plugin Contributions
    0

    Default Re: PHP syntax help

    It's still not working.

    The code is fine - it doesn't seem like it can match the word "Size." I can get it to echo $options_name as Size, so there's gotta be something else missing... I tried both upper & lower cases. It would be really cool if I can get this to work...

 

 

Similar Threads

  1. Help with PHP syntax on sidebox
    By sunflowertami in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 24 Aug 2008, 12:34 PM
  2. Help with PHP syntax please?
    By sunflowertami in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 17 Jun 2008, 11:48 AM
  3. Please help! php syntax needed to call images!
    By Vood in forum General Questions
    Replies: 3
    Last Post: 31 Oct 2007, 09:59 PM
  4. Easy PHP syntax question -- help please?
    By magicpants in forum General Questions
    Replies: 2
    Last Post: 17 Jan 2007, 02:31 PM
  5. Php Syntax Help - Custom Fields Switch
    By voltage in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 22 Jul 2006, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg