Jump to content

if logged in, display custom fields


sol2010

Recommended Posts

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}

Link to comment
Share on other sites

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} 

Link to comment
Share on other sites

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} 

Link to comment
Share on other sites

  • 2 months later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated