Sanora Dev Posted June 17, 2019 Share Posted June 17, 2019 Hello, I want to make some corrections on the registration form, but i can't find where to start. We only sell B2B, that's why i want to modify the registration form so that the company name and tax ID is mandatory (instead of optional) Also i want to add a mandatory field where the customer can add their number of chambre of commerce. Can anyone point me to the right direction? where to start or which file a need to modify to make this happen. Thanks, Elias 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 17, 2019 Share Posted June 17, 2019 Hi Elias, 14 minutes ago, Devias said: I want to make some corrections on the registration form, but i can't find where to start. generally it's either via admin settings, template edits or action hooks. 🙂 16 minutes ago, Devias said: We only sell B2B, that's why i want to modify the registration form so that the company name and tax ID is mandatory (instead of optional) that's either a template edit making those fields "required", or using an action hook similar to the one I posted in the thread below... in that case, it made tax id and country mandatory, but you should just need to change country to companyname in the hook code and you're good to go. 🙂 24 minutes ago, Devias said: Also i want to add a mandatory field where the customer can add their number of chamber of commerce. that will just need a Custom Client Field... Quote You can create client profile related fields in Setup > Custom Client Fields. These can be set to Show on Order Form if you want the client to enter them or left as admin area only for private entries. The client can view and edit the field values from the client area unless they are set to admin only. in your case, just ensure that you tick the "Required Field" and "Show on Order Form" checkboxes and it will be shown at checkout or when registering. 32 minutes ago, Devias said: Can anyone point me to the right direction? where to start or which file a need to modify to make this happen. if you ever needed to edit the checkout page, that should be checkout.tpl in your active orderform template folder... for registrations, it would be clientregister.tpl - though ideally if possible, try to use hooks as they should continue working after a WHMCS update, template edits may be lost. 0 Quote Link to comment Share on other sites More sharing options...
Sanora Dev Posted June 20, 2019 Author Share Posted June 20, 2019 (edited) On 6/17/2019 at 2:10 PM, brian! said: Hi Elias, generally it's either via admin settings, template edits or action hooks. 🙂 that's either a template edit making those fields "required", or using an action hook similar to the one I posted in the thread below... in that case, it made tax id and country mandatory, but you should just need to change country to companyname in the hook code and you're good to go. 🙂 that will just need a Custom Client Field... in your case, just ensure that you tick the "Required Field" and "Show on Order Form" checkboxes and it will be shown at checkout or when registering. if you ever needed to edit the checkout page, that should be checkout.tpl in your active orderform template folder... for registrations, it would be clientregister.tpl - though ideally if possible, try to use hooks as they should continue working after a WHMCS update, template edits may be lost. Hello Brian, Thanks for pointing out which files i need to modify the checkout. Your hook worked perfect and i got the tax id now mandatory. I want the company name te be mandatory to, so i used your hook and copy the code. You used &taxcode for the tax id, where can i find that code for the company name? I used this now: <?php # Make Field Required @ Checkout Hook # Written by brian! use App; add_hook('ShoppingCartValidateCheckout', 1, function ($vars) { $taxcode = App::getFromRequest('tax_id'); if (!$taxcode) { return Lang::trans('clientareaerrortaxid'); } $companyname = App::getFromRequest('companyname'); if (!$companyname) { return Lang::trans('clientareaerrorcompanyname'); } }); unfortunately this doesn't work. (tax id still works, but company name doesn't) Should i use the hook in a new file? but apart from this I have been able to adjust the checkout form to our wishes, thanks to your instructions. By the way: the topic that you linked to get the hook needed one correction. There was no quotation mark in the code after removing the optional text in the checkout.tpl. like this: <input type="text" name="tax_id" id="inputTaxId" class="field" placeholder="{lang key=\WHMCS\Billing\Tax\Vat::getLabel()} value="{$clientsdetails.tax_id}"{if $loggedin} readonly="readonly"{else} required{/if}> should be with a quotation mark after ::getLabel()}, <input type="text" name="tax_id" id="inputTaxId" class="field" placeholder="{lang key=\WHMCS\Billing\Tax\Vat::getLabel()}" value="{$clientsdetails.tax_id}"{if $loggedin} readonly="readonly"{else} required{/if}> So if anyone is wondering why you see the value= in your checkout form, you need to add the quotation mark.:) Thanks, Elias Edited June 20, 2019 by Devias 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 20, 2019 Share Posted June 20, 2019 (edited) 21 minutes ago, Devias said: Should i use the hook in a new file? that would work - the point being that you can only return once... you could tweak the one hook to cover all eventualities... <?php # Make Field Required @ Checkout Hook # Written by brian! use App; add_hook('ShoppingCartValidateCheckout', 1, function ($vars) { $taxcode = App::getFromRequest('tax_id'); $companyname = App::getFromRequest('companyname'); if (!$taxcode and !$companyname) { return [Lang::trans('clientareaerrortaxid'),Lang::trans('clientareaerrorcompanyname'),]; } elseif (!$taxcode) { return Lang::trans('clientareaerrortaxid'); } elseif (!$companyname) { return Lang::trans('clientareaerrorcompanyname'); } }); there would be a neater way to do it if you have a lot more conditions, but the above should work for your situation - and can be expanded if you need to force other fields to be required. 21 minutes ago, Devias said: So if anyone is wondering why you see the value= in your checkout form, you need to add the quotation mark.:) thanks for pointing that out - i've just edited the original thread to put that missing quotation mark in. Edited June 20, 2019 by brian! 0 Quote Link to comment Share on other sites More sharing options...
Sanora Dev Posted June 21, 2019 Author Share Posted June 21, 2019 21 hours ago, brian! said: that would work - the point being that you can only return once... you could tweak the one hook to cover all eventualities... <?php # Make Field Required @ Checkout Hook # Written by brian! use App; add_hook('ShoppingCartValidateCheckout', 1, function ($vars) { $taxcode = App::getFromRequest('tax_id'); $companyname = App::getFromRequest('companyname'); if (!$taxcode and !$companyname) { return [Lang::trans('clientareaerrortaxid'),Lang::trans('clientareaerrorcompanyname'),]; } elseif (!$taxcode) { return Lang::trans('clientareaerrortaxid'); } elseif (!$companyname) { return Lang::trans('clientareaerrorcompanyname'); } }); there would be a neater way to do it if you have a lot more conditions, but the above should work for your situation - and can be expanded if you need to force other fields to be required. thanks for pointing that out - i've just edited the original thread to put that missing quotation mark in. Thanks brian for (correcting) the code. Got it all working. Elias 0 Quote Link to comment Share on other sites More sharing options...
cosmin Posted July 10, 2019 Share Posted July 10, 2019 I use this hook and work with a little problem. After I finish to complete the forms, also VAT ID field and I press Finish order I get an error how the VAT ID field was empty. If I put again the VAT number and press Finish is working. How can I solve the problem to be viewed from first time? Thank you! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 10, 2019 Share Posted July 10, 2019 7 minutes ago, cosmin said: After I finish to complete the forms, also VAT ID field and I press Finish order I get an error how the VAT ID field was empty. If I put again the VAT number and press Finish is working. How can I solve the problem to be viewed from first time? when testing on your site (I changed it to UK and entered a GB VAT ID), I didn't see the issue occurring - is it happening all the time, or just occasionally ? 0 Quote Link to comment Share on other sites More sharing options...
cosmin Posted July 11, 2019 Share Posted July 11, 2019 Few days ago I have changed the module for registration .ro domains and the previous one had some hooks. I think from there was the problem because now work very well. Thanks for info! 😁 0 Quote Link to comment Share on other sites More sharing options...
airbytesnet Posted June 27, 2022 Share Posted June 27, 2022 Hi Brian, how will be possible to add the code below to the register form? I would like to have same rules for the page register.php (Create a new account), if the customer register first and then order I would need to have company name and vat number from the beginning. thank you! <?php # Make Field Required @ Checkout Hook # Written by brian! use App; add_hook('ShoppingCartValidateCheckout', 1, function ($vars) { $taxcode = App::getFromRequest('tax_id'); $companyname = App::getFromRequest('companyname'); if (!$taxcode and !$companyname) { return [Lang::trans('clientareaerrortaxid'),Lang::trans('clientareaerrorcompanyname'),]; } elseif (!$taxcode) { return Lang::trans('clientareaerrortaxid'); } elseif (!$companyname) { return Lang::trans('clientareaerrorcompanyname'); } }); 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.