Post by Micas » Tue Aug 28, 2018 7:29 pm

Hi,

When the customer enters their email address there is sometimes a space at the end of the email which throws up an error on the checkout so I want to trim the space from the end of the email before is validated from the below code;

if ((utf8_strlen($this->request->post['personal_details']['email']) > 96) || !filter_var($this->request->post['personal_details']['email'], FILTER_VALIDATE_EMAIL)) {

I have tried and tried to do this but don't understand php so any help would be much appreciated.

Thanks,

New member

Posts

Joined
Sat Sep 02, 2017 12:28 am

Post by straightlight » Tue Aug 28, 2018 8:13 pm

What are the results when implementing the changes? Did you cleared the cache by following the FAQ: viewtopic.php?f=176&p=732808#p718325 ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Micas » Tue Aug 28, 2018 9:32 pm

I apologise if I have broken the forum rules but I wasn't aware I was doing anything wrong and have spent literally days trying to sort this out myself, but with my limited knowledge I just need a little help, I did everything that you recommended but as I say I'm no expert so may have done something wrong, here are the steps that I took.

I followed your instructions changing the existing lines of code to the below in system/library/mail.php

public function setTo($to) {
$this->to = trim($to);
}

public function setFrom($from) {
$this->from = trim($from);
}

I then cleared the opencart cache and also the modification cache, I also cleared the browser history/cookies etc but the problem still persists
For example if there is a space at the end of the email address when the customer is checking out (which is caused by the predictive input from mobile phones - a space is generated at the end of each word ready for the next word to space them apart) the customer is not allowed to proceed through the checkout and they abandon their cart as they don't know why their email isn't being accepted.

Also, I have noticed that if there is a space at the end of any of the other address fields this doesn't cause any problems - it just seems to be the email field.

Thanks

New member

Posts

Joined
Sat Sep 02, 2017 12:28 am

Post by straightlight » Tue Aug 28, 2018 9:42 pm

This situation is getting a bit clearer. In catalog/model/account/customer.php file,

find all instances of:

Code: Select all

$this->db->escape(utf8_strtolower($email))
replace all with:

Code: Select all

$this->db->escape(trim(utf8_strtolower($email)))
This should resolved the issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Micas » Tue Aug 28, 2018 10:08 pm

I've changed the code as above but the problem is still persisting - you can replicate it on the desktop view by just adding a space at the end of the email field, please see the attached screenshot.

Attachments

2018-08-28 14_50_54-Checkout.png

2018-08-28 14_50_54-Checkout.png (29.46 KiB) Viewed 6173 times


New member

Posts

Joined
Sat Sep 02, 2017 12:28 am

Post by straightlight » Tue Aug 28, 2018 10:18 pm

So, with an elaborated screenshot posted in compliance of the forum rules, you are referring to the checkout guest emails. In catalog/controller/checkout/guest.php file,

find:

Code: Select all

if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
add above:

Code: Select all

$this->request->post['email'] = trim($this->request->post['email']);
Then, clear the OC cache: viewtopic.php?f=176&p=733002#p718325 . See if that rectifies the issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Micas » Tue Aug 28, 2018 10:49 pm

Ok - Regarding the below code:

$this->request->post['email'] = trim($this->request->post['email']);

Were does it need to go in relation to this code:

if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {

For example, does it need to go above/below or at the end of it etc

Thanks,

New member

Posts

Joined
Sat Sep 02, 2017 12:28 am

Post by straightlight » Tue Aug 28, 2018 11:03 pm

As mentioned on my previous post:
add above:

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Micas » Tue Aug 28, 2018 11:33 pm

Thank you very much for your help, this has now resolved the issue that I was having.

New member

Posts

Joined
Sat Sep 02, 2017 12:28 am

Post by straightlight » Tue Aug 28, 2018 11:36 pm

Thanks for the feedback. However, see if the following statement will work as there's also a way to do this for the entire platform. In system/library/request.php file,

find:

Code: Select all

public function clean($data) {
		if (is_array($data)) {
			foreach ($data as $key => $value) {
				unset($data[$key]);

				$data[$this->clean($key)] = $this->clean($value);
			}
		} else {
			$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
		}

		return $data;
	}
replace with:

Code: Select all

public function clean($data) {
		if (is_array($data)) {
			foreach ($data as $key => $value) {
				unset($data[$key]);

				$data[$this->clean($key)] = $this->clean($value);
			}
			
			$this->arrayMapRecursive('trim', $data);
			
		} else {
			$data = htmlspecialchars(trim($data), ENT_COMPAT, 'UTF-8');
		}

		return $data;
	}
	
	// Source: https://stackoverflow.com/questions/47298576/how-do-i-remove-surrounding-spaces-from-each-value-in-multidimensional-array-rec
	protected function arrayMapRecursive(callable $func, array $array) {
            return filter_var($array, \FILTER_CALLBACK, ['options' => $func]);
        }
Remove the previous email instruction line from the previous post and see if the new added code also resolves the issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Micas » Wed Aug 29, 2018 12:28 am

Straightlight that is fantastic - I have tested on both the checkout as guest and also the register account checkout and it works perfectly on both.

Thanks again for your time and help.

New member

Posts

Joined
Sat Sep 02, 2017 12:28 am

Post by straightlight » Wed Aug 29, 2018 12:30 am

Outstanding. Thanks for reviewing this. The only problematic it may create would be with the insistent remote API providers requiring to add some space in their encoded URL strings. Since it might be the case, ensure to monitor your error / server access logs regarding URL structures if customers contacts you about a failed transaction.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by redlik7 » Thu Feb 20, 2020 8:54 pm

HI,
I know this thread is bit outdated. I had an issue with "not valid email" registration error and tried the code from the suggestion above - changing the piece inside register.php file. It worked fine on the email fields but we started getting all sorts of errors on the front and back-end and I had to revert back to original file. I'm using v. 3.0.3.1 with Journal 3.
Should that code be updated to work?

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Thu Feb 20, 2020 8:57 pm

redlik7 wrote:
Thu Feb 20, 2020 8:54 pm
HI,
I know this thread is bit outdated. I had an issue with "not valid email" registration error and tried the code from the suggestion above - changing the piece inside register.php file. It worked fine on the email fields but we started getting all sorts of errors on the front and back-end and I had to revert back to original file. I'm using v. 3.0.3.1 with Journal 3.
No error logs provided.
Should that code be updated to work?
The code itself works, according to the above statement.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by redlik7 » Thu Feb 20, 2020 10:13 pm

straightlight wrote:
Thu Feb 20, 2020 8:57 pm
redlik7 wrote:
Thu Feb 20, 2020 8:54 pm
HI,
I know this thread is bit outdated. I had an issue with "not valid email" registration error and tried the code from the suggestion above - changing the piece inside request.php file. It worked fine on the email fields but we started getting all sorts of errors on the front and back-end and I had to revert back to original file. I'm using v. 3.0.3.1 with Journal 3.
No error logs provided.
Should that code be updated to work?
The code itself works, according to the above statement.
I got these errors on the front-end (screenshots)
Image
Image
and this in the errors log:

Code: Select all

2020-02-20 10:55:38 - PHP Warning:  Cannot modify header information - headers already sent by (output started at osmarine.ie/system/framework.php:42) in osmarine.ie/system/framework.php on line 108
2020-02-20 10:55:38 - PHP Warning:  Invalid argument supplied for foreach() in /storageosm/modification/admin/controller/catalog/product.php on line 1252
2020-02-20 10:55:38 - PHP Warning:  Invalid argument supplied for foreach() in /storageosm/modification/admin/model/catalog/product.php on line 146
2020-02-20 10:55:38 - PHP Warning:  Cannot modify header information - headers already sent by (output started at /marinedistributors.ie/osmarine.ie/system/framework.php:42) in //marinedistributors.ie/storageosm/modification/system/library/response.php on line 36
2

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Thu Feb 20, 2020 10:15 pm

Which PHP version are you using?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by redlik7 » Thu Feb 20, 2020 10:18 pm

straightlight wrote:
Thu Feb 20, 2020 10:15 pm
Which PHP version are you using?
it's 7.3.14

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Thu Feb 20, 2020 10:20 pm

Perhaps some changes with the array_map function were applied from the industry since. May be looking on StackOverFlow by using Google to find the most recent solution. :ponder:

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by redlik7 » Thu Feb 20, 2020 10:22 pm

straightlight wrote:
Thu Feb 20, 2020 10:20 pm
Perhaps some changes with the array_map function were applied from the industry since. May be looking on StackOverFlow by using Google to find the most recent solution. :ponder:
I can downgrade the version, if you think that's going to help. But to which version?

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Thu Feb 20, 2020 10:23 pm

Rather understand the new changes than reverting back to the old ones would be better in this case since the request constructor is a library file that is totally centralized throughout the platform.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 19 guests