Results 1 to 5 of 5

Thread: New custom field based on existing values

  1. #1
    Join Date
    Mar 2008
    Posts
    60

    Default New custom field based on existing values

    Hi -

    We would like to add a new custom field to our client's product details page (clientarea.php?action=productdetails).

    The new custom field requires concatenating three existing custom fields along with some text.

    So, the new custom field would be something like:

    field1.value + 'sometext ' +field2.value+'sometext '+field3.value

    The existing fields are all text strings.

    Looking at the clientareaproductdetails.tpl, I'm pretty stumped as to how this can be done.

    {foreach from=$productcustomfields item=customfield}
    <div class="col2half">
    <p><h4>{$customfield.name}:</h4> {$customfield.value}</p>
    </div>


    Can anyone provide some direction for this?

    Thanks.

  2. #2
    Join Date
    Feb 2009
    Location
    Atlanta, GA
    Posts
    1,683

    Default

    Code:
    {foreach from=$productcustomfields item=customfield}
    <input type="hidden" id="{$customfield.name}" value="{$customfield.value}" />
    {/foreach}
    
    <h4>Field Data:</h4><span id="customfieldsval"></span>
    
    <script language="javascript">
    {literal}
    $(document).ready(function() {
      var field1 = $('#customfield1').val();
      var field2 = $('#customfield2').val();
      $('#customfieldsval').html(customfield1 + "Some random text here" + customfield2);
    });
    {/literal}
    </script>
    Replace customfield1 and customfield2 with the actual field names.

  3. #3
    Join Date
    Mar 2008
    Posts
    60

    Default

    Hi laszlof -

    Thanks for that.

    I'll give it a go.

  4. #4
    Join Date
    Mar 2008
    Posts
    60

    Default

    Quote Originally Posted by laszlof View Post
    {foreach from=$productcustomfields item=customfield}
    <input type="hidden" id="{$customfield.name}" value="{$customfield.value}" />
    {/foreach}

    <h4>Field Data:</h4><span id="customfieldsval"></span>

    <script language="javascript">
    {literal}
    $(document).ready(function() {
    var field1 = $('#customfield1').val();
    var field2 = $('#customfield2').val();
    $('#customfieldsval').html(customfield1 + "Some random text here" + customfield2);
    });
    {/literal}
    </script>


    Replace customfield1 and customfield2 with the actual field names.


    Hi -

    It doesn't seem to be getting the vars:


    Code:
    {foreach from=$productcustomfields item=customfield}
                    <div class="col2half">
                        <p><h4>{$customfield.name}:</h4> {$customfield.value}</p>
                    </div>
                    {/foreach}
                    <h4>Custom Field:</h4><span id="customfieldsval"></span>
    <script language="javascript">
    {literal}
    $(document).ready(function() {
      var field1 = $('#ANAME').val();
      var field2 = $('#BNAME').val();
      $('#customfieldsval').html("http://domain.com/index.php?name1=" + ANAME + "&name2=" + BNAME);
    });
    {/literal}
    </script>

    Does not return anything.

    I tried using field1 and field2 as well:


    Code:
    {foreach from=$productcustomfields item=customfield}
                    <div class="col2half">
                        <p><h4>{$customfield.name}:</h4> {$customfield.value}</p>
                    </div>
                    {/foreach}
                    <h4>Custom Field:</h4><span id="customfieldsval"></span>
    <script language="javascript">
    {literal}
    $(document).ready(function() {
      var field1 = $('#ANAME').val();
      var field2 = $('#BNAME').val();
      $('#customfieldsval').html("http://domain.com/index.php?name1=" + field1 + "&name2=" + field2);
    });
    {/literal}
    </script>

    This returns the text portion of the string, but the vars return as undefined:

    Code:
    http://domain.com/index.php?name1=undefined&name2=undefined
    I thought this might be because it is outside of the $productcustomfields section, but even if I include the code within the loop (repeating it after every other field) I get the same results.

  5. #5
    Join Date
    Mar 2008
    Posts
    60

    Default

    Agghh!!

    I left off


    Code:
    {foreach from=$productcustomfields item=customfield}
    <input type="hidden" id="{$customfield.name}" value="{$customfield.value}" />
    {/foreach}
    from your code.

    All good now - works great.

    Thanks again!

Similar Threads

  1. Possible? Set the value of a custom field based on the domain option selected
    By writeclickmedia in forum Customisation & Integration Questions
    Replies: 0
    Last Post: 10-13-10, 11:38 PM