Jump to content
Devias

Customisations on the registration form

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

F9O3YLF.png

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.

Share this post


Link to post
Share on other sites
Posted (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.

F9O3YLF.png

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 by Devias

Share this post


Link to post
Share on other sites
Posted (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 by brian!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites

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! 😁

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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