Jump to content

Registration Form Vat Number And E-Mail Address Verification


Max

Recommended Posts

An attempt at modifying the sign-up form to add VAT number and e-mail address verification.

 

  • Asks the user if he is a private individual or company
  • Hides company name input field if private individual (to prevent the user entering things like "-" or "NA", which can cause problems with domain registrations.)
  • If the user is an European company, he can enter his VAT number and press "validate", the system will then verify the number and fill in the company name and address information (if available) automatically.
  • If a valid EU VAT number is entered, and the customer is in a different country than you, he will not be charged VAT (reverse charge procedure)
  • The e-mail address is verified by sending an 8 character verification code to it, that must be entered by the user to proof the address is correct.

 

vat_number_validation2.jpg

 

 

vat_number_validation.jpg

 

 

 

 

blesta_email_verification.jpg

 

 

Requires PHP SOAP extension (to communicate with the European Union's VIES VAT number validation service), and that the default country in the Blesta settings is set to your own company location.

 

Diff (file changes): http://www2.noc-ps.com/dl/blesta-3.1-signup-form.diff

SQL (extra e-mail template): http://www2.noc-ps.com/dl/blesta-3.1-signup-form.sql

Link to comment
Share on other sites

Thanks, only issue I have is haha that diff file looks very confusing

 

Yeah, the diff is not that human readable, due to me moving the input fields on the sign-up form around (the "country", "tax_id" and "company" fields were moved to the top of the form)

 

 

when going to edit the pdt file.

 

Generally it is not necessary to edit the files manually though.

patch is your friend.

$ cd blesta-3.1.0
$ patch -p1 < blesta-3.1-signup-form.diff
patching file blesta/components/invoice_templates/default_invoice/default_invoice_pdf.php
patching file blesta/components/invoice_templates/default_invoice/language/en_us/default_invoice.php
patching file blesta/plugins/order/controllers/main.php
patching file blesta/plugins/order/language/en_us/main.php
patching file blesta/plugins/order/views/templates/standard/language/en_us/main.php
patching file blesta/plugins/order/views/templates/standard/main_signup.pdt
Link to comment
Share on other sites

  • 5 months later...

Hi Max,

 

I'm really interested in the email verification portion of this, but I'm a bit of an amateur when it comes to code so I'm not really sure what aspects of the diff file are expendable.

 

In short I want to take what you've done minus the VAT aspect and to add a validation rule to the email address field.

 

 

I'd need anyone signing up to prove that they are uk students, so the validation rule would be that the email address has to end in .ac.uk as these tlds are reserved exclusively for educational institutions. So essentially they'd enter a .ac.uk email address then hit "send verification code" and this will check the validity of the email address before sending out the verification email.

 

Any pointers in achieving this would be greatly appreciated.

Link to comment
Share on other sites

I'd need anyone signing up to prove that they are uk students, so the validation rule would be that the email address has to end in .ac.uk as these tlds are reserved exclusively for educational institutions. So essentially they'd enter a .ac.uk email address then hit "send verification code" and this will check the validity of the email address before sending out the verification email.

 

Any pointers in achieving this would be greatly appreciated.

 

Apply patch, and change:

 

if (!filter_var($email, FILTER_VALIDATE_EMAIL))

 

to:

 

if (!filter_var($email, FILTER_VALIDATE_EMAIL) || !preg_match('/\.ac\.uk$/i', $email) )

Link to comment
Share on other sites

  • 1 month later...

Hi max, firstly thanks for your previous message.

 

I've been working on integrating the email verification part of the diff manually with 3.3b1. The integration seems to be fine but i think some of the calls that worked in 3.1 no longer work.

 

e.g. this line is broken

 

if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$this->outputAsJson(array('success' => false));
return false;
}
 
results in the following no matter what is entered into the email field.
"E-mail address invalid"
but if the line is removed.
"Verification e-mail sent. Please check your e-mail."
 
 
however the email itself doesn't actually send.
 
i'm pretty sure the problem lies somewhere in the lines under added to order/controllers/main.php
 
	/**
	 * AJAX method that sends verification e-mail to customer
	 */
	public function sendVerificationEmail()
	{
		if (!$this->isAjax())
			$this->redirect($this->base_uri . "plugin/order/");

		$email = $_POST['email'];
		if (!filter_var($email, FILTER_VALIDATE_EMAIL))
		{
			$this->outputAsJson(array('success' => false));
			return false;
		}

		if ($email != $this->Session->read('verification_email'))
		{
			$code  = dechex(mt_rand());
			$this->Session->write('verification_email', $email);
			$this->Session->write('verification_code', $code);
		}
		else
		{
			$code = $this->Session->read('verification_code');
		}

		Loader::loadModels($this, array("Emails"));
		$template_name = "account_email_verification";
		$tags = array(
			'contact' => $_POST,
			'company' => $this->Companies->get($this->company_id),
			'code' => $code 
		);
		
		$this->Emails->send($template_name, $this->company_id, null, $email, $tags);
		
		$this->outputAsJson(array('success' => true));
		return false;
	}

any idea what may need to be updated firstly for the validation filter not to result in errors and secondly for the email to actually send?

 

thanks.

Link to comment
Share on other sites

Hi max, firstly thanks for your previous message.

 

I've been working on integrating the email verification part of the diff manually with 3.3b1. The integration seems to be fine but i think some of the calls that worked in 3.1 no longer work.

 

e.g. this line is broken

 

if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$this->outputAsJson(array('success' => false));
return false;
}
 
results in the following no matter what is entered into the email field.
 
 
 
"E-mail address invalid"
but if the line is removed.
"Verification e-mail sent. Please check your e-mail."
 
 
however the email itself doesn't actually send.

 

Install Firebug and check what is being send by your browser to Blesta. Does it send the e-mail address you entered?

Link to comment
Share on other sites

Hi Max,

 

Found the problem in the diff, there was a line that needed changing

 

$(document).blestaRequest('POST', '<?php echo $this->Html->safe($this->base_uri . "plugin/order/main/sendverificationemail/" . $this->Html->ifSet($order_form->label));?>', $('#tax_id').closest('form').serialize(),

 

changed to

 

$(document).blestaRequest('POST', '<?php echo $this->Html->safe($this->base_uri . "plugin/order/main/sendverificationemail/" . $this->Html->ifSet($order_form->label));?>', $('#email').closest('form').serialize(),

 

Thank you so much it works an absolute treat. You're the best =]

 

Just one more quick thing... I only want it to appear for company id 2 any ideas?

Link to comment
Share on other sites

  • 3 months later...

Does this work in Blesta 3.3.2?  

 

Haven't tested it with newer releases, although I would expect it to work.

Are you having any problems with it?

 

 

We're currently not actually using Blesta ourselves, but still our custom developed billing system, we would like to replace one day.

This was more a proof of concept to see how easy it was to modify Blesta for some of our needs.

Not making any commitment to update it. Open up a feature request for an official replacement if the functionality is critical for your business.

Link to comment
Share on other sites

Thanks Max.

 

No worries.  It didn't patch correctly, but I think I've found the issue, some of the file naming conventions have changed.  Haven't look into it yet as to whether there are any actual changes within the file which will effect.

 

Just evaluating Blesta at the moment.  Not sure if it's up to my requirements or not yet. 

 

Cheers,

Link to comment
Share on other sites

Does this work in Blesta 3.3.2?  

 

It worked a treat in 3.2, but as of 3.3/3.4 resulted in the following error:

 

Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) in /blesta/plugins/order/controllers/main.php on line 125

 

 

which for me is the first line in this block of code:

				if ($this->post['email'] != $this->Session->read('verification_email')
				    || strtolower(trim($this->post['email_verification_code'])) != $this->Session->read('verification_code'))
				{
					$errors = array('email' => array('invalid' => Language::_("Signup.!error.email_verification_incorrect", true)));
				}
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.

Loading...
×
×
  • Create New...