Jump to content

Placing individual custom client fields on the registration form...


Chris74

Recommended Posts

Hi I'm trying to add custom client fields to the registration form individually, rather than at the bottom of the page, but there is no documentation on how to specify individual custom client fields on the templates, only the "foreach" option, which I don't want to use because it places them all together, under the main form.

 

I want to put the custom field for the vat number, directly under the company name field on the signup form and a further custom field at the bottom right, under the telephone number. I think it's reasonable that we would want to put these custom fields wherever we want to, but I can't find a way of doing it.

 

Is there a way?

Link to comment
Share on other sites

Hi, sorry for bumping my own post here but can someone please clarify for me the following statement...

 

 

It is possible to create custom client fields as described here in the WHMCS documentation...

 

http://docs.whmcs.com/Custom_Fields

 

However, the only way that they can be used, is to choose the option to display them on the order form, so that they appear, bunched together at the bottom of the page.

 

These fields cannot be placed individually anywhere.

 

Is that correct?

 

I have already opened a ticket to ask about this, but the reply I got back was puzzling - I was directed to enter {debug} into a template file to see a list of template variables, which I'm quite sure is not an answer to my question.

 

If anyone would be so kind as to put me out of my misery here, I'd appreciate it. Can the individual custom client fields actually be used on their own?

Link to comment
Share on other sites

Hello,

 

They can be placed where you would like. You would still need the foreach statement, however what I've done is:

 

[1] Created two custom client fields, "Test1" & "Test2"

[2] Went into ./templates/{$template}/clientregister.tpl

[3] Modified the foreach loop:

 

{foreach key=num item=customfield from=$customfields}
{/foreach}

 

[4] Created an if statement dependent on the customfield.name variable:


{if $customfield.name eq "Test2"}
<div class="control-group">
           <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
               <div class="controls">
                   {$customfield.input} {$customfield.description}
               </div>
       </div>
{else}
FAIL
{/if}

 

From here I can ultimately place this block of code anywhere in my template, wrap it with <table> tags if I needed, etc & create additional if statements in the specific locations I want a specific table, and simply adjust the $customfield.name eq "$fieldname" to match.

Link to comment
Share on other sites

Hi Chris,

 

That's a decent workaround, thank you very much for posting those details.

 

I must add some constructive criticism though. It is a real shame you haven't included a simple way to add any custom client field anywhere. After setting them up, the first thing I did was head to the documentation to find out how I could add them individually on the form, only to find that there is no immediate solution for that. It's taken me four days to finally get an answer, even after contacting support and I can't imagine it being that difficult for you to add in this functionality which is really a basic requirement.

Link to comment
Share on other sites

Hello,

 

Well, the functionality itself is there. It's just coding it with the smarty templates to cater it to the overall community, and allow a customizable template structure (smarty) to further detail the order form you wish to have.

 

If we shipped the smart template with syntax where there was an if statement for each potential customfield.id, the specific template file would be massive. The foreach statement allows custom fields for everyone to be displayed in a relatively attractive fashion, and customizable smarty templates allow users like yourself to further extend that.

Link to comment
Share on other sites

Hello,

 

Well, the functionality itself is there. It's just coding it with the smarty templates to cater it to the overall community, and allow a customizable template structure (smarty) to further detail the order form you wish to have.

 

If we shipped the smart template with syntax where there was an if statement for each potential customfield.id, the specific template file would be massive. The foreach statement allows custom fields for everyone to be displayed in a relatively attractive fashion, and customizable smarty templates allow users like yourself to further extend that.

 

I'm happy that I've got a solution now, thank you for that - but I shouldn't have to jump through hoops in order to simply add a field to a form where I want it. It really is simply just a poor implementation of the custom field functionality.

 

From my point of view, all I wanted to do was use the custom fields your product allowed me to create - but that proved to be impossible without asking twice on this forum and also raising a support ticket that took two days to respond to (which ended up fruitless because the answer I received from your support was not relevant to the question I asked).

 

I don't see why it wouldn't be possible to allow the creation of new client fields that can simply be used in the form like the rest of them - i.e $custom_field1 or $custom_field2. You are suggesting that you've reached the limitations of PHP and Smarty here and that there is no better way of doing it. I'm sorry but I don't believe that.

Link to comment
Share on other sites

Hello,

 

I'm not suggesting anything of the sort. I'm glad I was able to assist you in figuring out your template question.

 

Ok, I guess you were suggesting that in order to "cater for the overall community", it's easier to lump all the custom fields together at the bottom of the form - as an "out of the box" solution so anyone with little technical knowledge could use those fields without having to edit the templates. I understand that.

 

While at the same time allowing those with programming skills to manipulate the smarty templates, like in the example you showed above. I understand that too.

 

At least the way to do it is now documented here in the forum for anyone else who needs to know. Thank you for your time.

Link to comment
Share on other sites

  • 2 months later...

Apologies for bringing this back up - but your workaround seemed to work perfectly when I was using only one custom field, but now I have three, it won't display them all at the same time. I want to place three different fields in different places on the form. Can you advise how to do that?

Link to comment
Share on other sites

Apologies for bringing this back up - but your workaround seemed to work perfectly when I was using only one custom field, but now I have three, it won't display them all at the same time. I want to place three different fields in different places on the form. Can you advise how to do that?

what you could do is call the "foreach" loop each time you want to add a custom field... i've tested this on viewcart.tpl, but I assume it would work on clientregister.tpl as stated above.

 

so work out where in the form you want to place the custom field (e.g Custom1) and add the following code...

 

{foreach key=num item=customfield from=$customfields}

{if $customfield.name eq "Custom1"}

<tr><td>{$customfield.name}</td><td>{$customfield.input}</td></tr>

{/if}{/foreach}

this will display the specified "Custom1" custom field, but none of the others...

 

then find where you want to add the second custom field, and add this...

 

{foreach key=num item=customfield from=$customfields}

{if $customfield.name eq "Custom2"}

<tr><td>{$customfield.name}</td><td>{$customfield.input}</td></tr>

{/if}{/foreach}

etc etc... you may have to tweak the <tr><td> tags to match the surrounding table layout.

 

tbh, I couldn't get Chris' method to work when wanting to use custom fields in different places, i.e just one foreach loop with various if statements placed where you want the custom fields to be... perhaps i'm missing something, but I think the above method works - though i'm sure you'll be back if it doesn't :)

Link to comment
Share on other sites

  • 1 year later...

I'm having trouble with this.

 

I am able to put:

 

{if $product.customfields}{foreach key=custnum item=customfields from=$product.customfields}

{$customfields.name}: {$customfields.value}<br />

{/foreach}{/if}

 

in my viewcart.tpl just fine and all of the custom fields display.

 

However, I only want to display one custom field on the cart page so I used the code that brian suggested above.

 

{foreach key=num item=customfield from=$customfields}

{if $customfield.name eq "Custom1"}

<tr><td>{$customfield.name}</td><td>{$customfield.input}</td></tr>

{/if}{/foreach}

 

I replaced Custom1 with the name of the custom field I'm trying to display. For some reason, this doesn't display anything.

 

How can I troubleshoot this?

 

*

If you'd like to inspect the code I've added to my viewcart.tpl, go http://www.jackrabbit.host, order a hosting package and on the cart page, look directly under the hosting packages [Edit Configuration] [Remove]

 

For the custom fields, I'm using the softaculous auto install hook and trying to display the "script" value. (I've given a custom name "install" rather than "script")

Edited by JackRabbit
Link to comment
Share on other sites

the original code is for custom client fields, it seems you want to tweak it for product custom fields...

 

if you say your first block of code works fine and it shows all product custom fields...

 

{if $product.customfields}{foreach key=custnum item=customfields from=$product.customfields}
{$customfields.name}: {$customfields.value}<br />
{/foreach}{/if}

then it should still work when you throw the {if} statement into it...

 

{if $product.customfields}{foreach key=custnum item=customfields from=$product.customfields}
{if $customfield.name eq "Custom1"}
{$customfields.name}: {$customfields.value}<br />
{/if}{/foreach}{/if}

the only difference I can see is that when you tried to use my code, you forgot to change the "from" entry to $product.customfields - my code will check for client custom fields (which you seem to have none), but you want to check the $products array to see if there are custom fields for the product(s) in the cart.

 

if that doesn't fix it, come back and i'll take a closer look.

Link to comment
Share on other sites

Thanks Brian. I've added the code you suggested and it's still not working.

 

{if $product.customfields}{foreach key=custnum item=customfields from=$product.customfields}
{if $customfield.name eq "Install"}
{$customfields.name}: {$customfields.value}<br />
{/if}{/foreach}{/if}

 

This code is below the edit hosting package link in the viewcart.tpl if you'd like to look.

Link to comment
Share on other sites

ok this was driving me mad for 10 minutes - it looked fine, but doesn't work... then I noticed the missing 's' in the {if} statement of your code... :roll:

 

try this...

 

{if $product.customfields}
   {foreach key=custnum item=customfields from=$product.customfields}
       {if $customfields.name eq "Install"}
           {$customfields.name}: {$customfields.value}<br />
       {/if}
   {/foreach}
{/if}

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