Jump to content

is it possible let whmcs to set certain custom value as X when creating account ?


rob2

Recommended Posts

Hi,

 

with the custom field feature,

 

i add certain custom field with admin only and Required Field,

 

but i do not need client to choose it and i hope it be X option directly.

 

 

with my checking.whmcs will not automatically create the field data for the client and set the X option for it,

 

i want to ask if any way that the new client registing or make ordering,

 

when whmcs get the registering call,it will let the hook to choose the custom field as X option and generate the value for the client/and save in database directly,

 

is it possible ?

 

 

thank you

Link to comment
Share on other sites

another option would be a template edit to checkout.tpl (and/or clientregister.tpl).

 

firstly, you would untick the "Admin Only" value in the custom client field setup, and tick the "Show On Order Form" option instead - also, I don't think it needs to be a required field as the client is not going to see it. :)

 

so using standard_cart/checkout.tpl as an example, the following code shows the custom fields...

 

                    {if $customfields}
                       <div class="sub-heading">
                           <span>{$LANG.orderadditionalrequiredinfo}</span>
                       </div>
                       <div class="field-container">
                           <div class="row">
                               {foreach $customfields as $customfield}
                                   <div class="col-sm-6">
                                       <div class="form-group">
                                           <label for="exampleInputEmail1">{$customfield.name}</label>
                                           {$customfield.input}
                                           {if $customfield.description}
                                               <span class="field-help-text">
                                                   {$customfield.description}
                                               </span>
                                           {/if}
                                       </div>
                                   </div>
                               {/foreach}
                           </div>
                       </div>
                   {/if}

but it we change that, we can hide the custom field you want to pass with a default value, and it should be passed when the client submits the order...

 

                    {if $customfields}
                       <div class="sub-heading">
                           <span>{$LANG.orderadditionalrequiredinfo}</span>
                       </div>
                       <div class="field-container">
                           <div class="row">
                               {foreach $customfields as $customfield}
                                   {if $customfield.id neq '42'}
                                       <div class="col-sm-6">
                                           <div class="form-group">
                                               <label for="exampleInputEmail1">{$customfield.name}</label>
                                               {$customfield.input}
                                               {if $customfield.description}
                                                   <span class="field-help-text">
                                                       {$customfield.description}
                                                   </span>
                                               {/if}
                                           </div>
                                       </div>
                                   {else}
                                       {$customfield.input|replace:'text':'hidden'|replace:'value=""':'value="rob2"'}
                                   {/if}
                               {/foreach}
                           </div>
                       </div>
                   {/if}

for this to work, you'll need to know either the ID or name of your customfield (you can get either from the source code in the browser) - in the above example, customfield #42 is a text field and the code will hide it from the client and change it to a hidden field with a default value of "rob2" - basically, you just need to edit the ID number in the code and the default value that you want to pass and this should work.

 

if it's not a text field, then the code might need a tweak - but if you aren't giving the customer a choice with this client custom field, then setting it as a text field would probably be simpler.

 

I haven't gone through testing this with an order, but looking at the resulting source code in the browser, the hidden field is there... although i've tested it in clientregister.tpl and it definitely works in there. :idea:

 

you would just need to use exactly the same {if} statement after the foreach loop and then add the {else} code before the closing {/foreach} loop... so in six/clientregister.tpl, it would look like this...

 

                {if $customfields}
                   {foreach from=$customfields key=num item=customfield}
                       {if $customfield.id neq '42'}
                           <div class="form-group">
                               <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                               <div class="control">
                                   {$customfield.input} {$customfield.description}
                               </div>
                           </div>
                       {else}
                           {$customfield.input|replace:'text':'hidden'|replace:'value=""':'value="rob2"'}
                       {/if}
                   {/foreach}
               {/if}

Link to comment
Share on other sites

@brian, would it be much easier with ActionHook?

it would certainly be better/cleaner to use an action hook - as it avoids the need for editing the template and repeating after a WHMCS update... all things being equal, a hook should always be preferable to a template edit. :idea:

 

but if the OP has no experience of writing hooks and wouldn't know where to start or want to learn, then editing the template is easier if it obtains the same goal.

 

I suppose I could have posted an example hook using ClientAdd instead, but the template tweak occurred to me as possibly being a quicker solution and was an alternative to your good suggestion. :)

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