sol2010 Posted January 30, 2012 Share Posted January 30, 2012 hi I have the following code on my viewcart.tpl page but it's not working.. Can anyone help? I've search the forums and can find nothing about displaying custom fields if the user is logged in. {foreach key=num item=customfield from=$customfields} {if $customfield.name eq "Mobile Number"} <tr> <td class="fieldarea">{$customfields[2].name} </td> <td>{if $loggedin}{$clientsdetails.customfields[2].name}{else} {$customfields[2].input|replace:'style="width:50%;"':'style="width:120px;"'} {$customfields[2].description}</td> </tr> {/if} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted January 30, 2012 Share Posted January 30, 2012 Why are you referencing array indexes within a foreach loop? That defeats the entire purpose of the foreach loop. For also forgot to close the if statement around the logged in variable. {foreach key=num item=customfield from=$customfields} {if $customfield.name eq "Mobile Number"} <tr> <td class="fieldarea">{$customfield.name} </td> <td>{if $loggedin}{$customfield.name}{else} {$customfield.input|replace:'style="width:50%;"':'style="width: 120px;"'} {$customfield.description}{/if}</td> </tr> {/if} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted January 30, 2012 Author Share Posted January 30, 2012 Why are you referencing array indexes within a foreach loop? That defeats the entire purpose of the foreach loop. For also forgot to close the if statement around the logged in variable. Thanks for your reply. Nice try with your code - I tried it but it doesn't work! Have you tested it? Well, it works fine when not logged in, but when logged in - no bananas! The same issue with my code, either using the foreach loop or not, the CF displays when not logged in, but when logged in, the info doesn't display. Here's my code again (as I understand it, using the id [2] specifies the CF - I realise you could do this as you've suggested just using the foreach argument too.) {foreach key=num item=customfield from=$customfields} {if $customfield.name eq "Mobile Number"} <tr> <td class="fieldarea">{$customfields[2].name} </td> <td> {$customfields[2].input|replace:'style="width:50%;"':'style="width:120px;"'}{$customfields[2].required}{$customfields[2].description}</td> </tr> {/if} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted January 30, 2012 Share Posted January 30, 2012 Nah, I didnt test it. what exactly are you trying to do? Not display the custom fields at all if the client is logged in? 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted January 30, 2012 Share Posted January 30, 2012 Also, what orderform template are you using? 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted January 30, 2012 Author Share Posted January 30, 2012 Also, what orderform template are you using? Hi I am using web20cart and the viewcart.tpl file I am trying to 1) display the custom field if the client is not logged in 2) if the client is logged in, populate the CF with their info Thanks 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted April 5, 2012 Author Share Posted April 5, 2012 Just thought I would update this for anyone else who may come across it. Basically, you can't display the custom fields on the checkout page, to the user if they are logged in. Seems to be a quirk of the system. For example, This works fine when the user reaches the checkout page but is not logged in: {foreach key=num item=customfield from=$customfields} {if $customfield.name eq "Mobile / Other Number"} <tr> <td class="fieldarea">{$customfields[2].name} </td> <td> {$customfields[2].input|replace:'style="width:50%;"':'style="width:120px;"'}{$customfields[2].required}{$customfields[2].description}</td> </tr> {/if} {/foreach} However, this does not work when the user is already logged in - i.e. it just doesn't show the custom field at checkout if they are logged in. I've experimented with : {foreach key=num item=customfield from=$customfields} {if $customfield.name eq "Mobile / Other Number"} <tr> <td class="fieldarea">{$customfields[2].name} </td> <td> {if $loggedin}{$customfields[2].value}{else} {$customfields[2].input|replace:'style="width:50%;"':'style="width:120px;"'}{$customfields[2].required}{$customfields[2].description}{/if}</td> </tr> {/if} {/foreach} But this does not work! Other than that, I got it working. Hope this may help someone. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.