JTA Posted February 3, 2017 Share Posted February 3, 2017 Hello WHMCS users! We're a Television Service Provider and not a hosting company. Due to my countries amazing laws and regulations, I need the "Company" field required as I'm using it for their Social Security Number. (No * i promise, LOL) Anyway, for me as a company I must require it for all online sales for residents on my country, so I was wondering if I could make it a required field for registrating? (I already renamed "Company" to "Kennitala",) Some people aren't filling it out, and it's costing my company a lot of time and effort in calling each and everyone of them and getting the information we need. We try call the customers 2-3 times before we have to suspend their service until they call us or fill out the field. So is this possible somehow? Best regards, Jon from Thor Telecom Iceland. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 4, 2017 Share Posted February 4, 2017 Hi Jon, Due to my countries amazing laws and regulations, I need the "Company" field required as I'm using it for their Social Security Number. (No * i promise, LOL)Anyway, for me as a company I must require it for all online sales for residents on my country, so I was wondering if I could make it a required field for registration? (I already renamed "Company" to "Kennitala",) Some people aren't filling it out, and it's costing my company a lot of time and effort in calling each and everyone of them and getting the information we need. We try call the customers 2-3 times before we have to suspend their service until they call us or fill out the field. So is this possible somehow? I should probably first mention that you should really have used a Client Custom Field for this purpose - you could have made it required in the admin settings and you wouldn't have needed to change your existing form fields to get the SSN from your customers. however, I assume you don't want to change that now - so there would be a few ways to make a field required during registration. if you want to do it in the checkout.tpl template, you could eithert add "required" to the Company form field... <input type="text" name="companyname" id="inputCompanyName" class="field" placeholder="{$LANG.orderForm.companyName} ({$LANG.orderForm.optional})" value="{$clientsdetails.companyname}"{if $loggedin} readonly="readonly"{else} required{/if}> if you want to do it in jQuery instead, you could add the code below to the beginning of 'checkout.tpl'... <script type='text/javascript'> $(window).load(function(){ $(function(){ $("#inputCompanyName").prop('required',true); }); }); </script> if you want to use the jQuery solution as an action hook, you could create a new .php file in /includes/hooks and paste the following code into it... <?php add_hook('ClientAreaHeadOutput', 1, function($vars) { if (App::getCurrentFilename()=='cart') { return "<script type='text/javascript'> $(window).load(function(){ $(function(){ $(\"#inputCompanyName\").prop('required',true); }); }); </script>"; } }); 0 Quote Link to comment Share on other sites More sharing options...
Hein Posted September 5, 2020 Share Posted September 5, 2020 Hey Brain, I just tried your hook version and it does require it but the field still shows (optional). Is there a way to change that, that you know of (we only work with business, so optional is really not what we want to show for a required field 😉 ) 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 5, 2020 Share Posted September 5, 2020 Hi @Hein 3 hours ago, Hein said: Is there a way to change that, that you know of (we only work with business, so optional is really not what we want to show for a required field 😉 ) there would be a handful of ways to do it - you could globally redefine, using Language Overrides, the $LANG.orderForm.optional language string for each language used - I think it's only used twice in the templates by default - company name and tax id form fields. another way would be to modify the above hook and replace the placeholder text with just the company name language string and not include the optional language string... <?php # Cart Company Name Field Requirement Hook # Written by brian! function cart_company_name_requirement_hook($vars) { if ($vars['templatefile'] == 'viewcart') { $companyname = Lang::trans('orderForm.companyName'); return <<<HTML <script>$('#inputCompanyName').prop({'required':true,'placeholder':"$companyname"});</script> HTML; } } add_hook("ClientAreaFooterOutput", 1, "cart_company_name_requirement_hook"); for completeness, I did post another hook last year that returns an error (in a custom language string) at checkout if the specified field is empty - it will show an error alert just like other required fields... if it wasn't for the "optional" part of your question, you could have used that hook - but your situation either requires the above hook to do both tasks, or you require the field with the hook below and modify the above hook to only change the placeholder. 0 Quote Link to comment Share on other sites More sharing options...
Hein Posted September 5, 2020 Share Posted September 5, 2020 Hey Brian, We actually removed it from the template now but I hate doing that as any new update ... well, we know those issue all too well, right?! 🙂 And changing with language override does indeed only change 2 but the other one Can be optional (there are plenty of legit companies that do not have a VAT number 😉 ) So, a solution with Only changing the company one with a hook would be perfect. I'll test and and let you know if that did it as I've seen the same question quite often before so I'm sure many would like simple and clean solution. 0 Quote Link to comment Share on other sites More sharing options...
Hein Posted September 5, 2020 Share Posted September 5, 2020 Yes! Thank you Brian!. That works a treat and didn't realise it could be done as simple as that 🙂 I'll check the other one out as a correct error message may actually be better but this works pretty sweet as is. Thanks mate 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 5, 2020 Share Posted September 5, 2020 10 minutes ago, Hein said: We actually removed it from the template now but I hate doing that as any new update ... well, we know those issue all too well, right?! 🙂 yep - the more things change, the more they stay the same. 🙄 30 minutes ago, Hein said: And changing with language override does indeed only change 2 but the other one Can be optional (there are plenty of legit companies that do not have a VAT number 😉 ) I didn't know if you needed/wanted to visibly tell users whether any fields are optional... I assume you're not telling them openly that some are required! 🙂 0 Quote Link to comment Share on other sites More sharing options...
HostT Posted March 19, 2021 Share Posted March 19, 2021 So the above options kinda worked for me, but I decided to use a different implementation by using the `ClientDetailsValidation` hook (to match native validation via PHP). The ClientAreaFooterOutput is used to remove the (Optional) label: https://gist.github.com/tripflex/9f0dcf4e8cc7c7a27aec41dad9629ac4 These forums suck so I had to post it on GitHub gist above. The other option would be to use the above `ClientAreaFooterOutput` to set required prop when the "Create New Account" radio button is clicked. This is required to remove the `required` prop when the user wants to login instead, otherwise it throws an HTML5 validation error on the company name field even if the user is just logging in: add_hook( "ClientAreaFooterOutput", 1, function( $vars ){ if ( $vars['templatefile'] == 'viewcart' || $vars['templatefile'] === 'clientregister' ) { $companyname = \Lang::trans( 'orderForm.companyName' ); return <<<HTML <script>jQuery( function($){ function smyles_set_company_required( set_required ){ var input_company_name = $('#inputCompanyName'); if( input_company_name.length ){ if( set_required ){ input_company_name.prop({'required':true,'placeholder':"$companyname"}); } else { input_company_name.removeAttr('required'); } } } $('input[name="custtype"][value="new"]').on( 'ifChanged', function(){ smyles_set_company_required( $(this).is(':checked') ); }); smyles_set_company_required( true ); var company_label = $('label[for="inputCompanyName"]'); if( company_label.length ){ var clean_label = company_label.text().replace(/\(Optional\)/g, ''); company_label.text( clean_label ); } });</script> HTML; } }); 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.