Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 1 Week, 3 Days, 13 Hours ago Remove blank spaces from Email in registration form
#1
Solved: 1 Week, 3 Days, 13 Hours ago
Looks like my average guests are quite noob and many of them keep adding a space at the end of their email address inside either Email field or Email Confirmation field, inside User Registration page.

When registration in submitted, MyBB prints an error claiming that emails are different, and my users give up with registration, which turns in losing forum members.

How can I add a code that checks if there are white spaces and removes them before comparing the two fields?
Reply
#2
Solved: 1 Week, 3 Days, 13 Hours ago
Hi,

make a backup of the file "member.php".

Now, in that file,  search for:
$email = htmlspecialchars_uni($mybb->get_input('email'));
$email2 = htmlspecialchars_uni($mybb->get_input('email2'));

(Lines 310 and 311)

And change it to:
$email = htmlspecialchars_uni(trim($mybb->get_input('email')));
$email2 = htmlspecialchars_uni(trim($mybb->get_input('email2')));


Note 1: Remeber to use a program like Notepad++ or similar to edit this file and save it without BOM.

Note 2: whenever you update your MyBB forum, if the "member.php" is updated, you'll have to change it again.
I don't answer questions about localhost forums or forums without URL, I'm not a seer.  Cool
Reply
#3
Solved: 1 Week, 3 Days, 13 Hours ago
(09-10-2019, 01:09 PM)NoRules Wrote: Hi,

make a backup of the file "member.php".

Now, in that file,  search for:
$email = htmlspecialchars_uni($mybb->get_input('email'));
$email2 = htmlspecialchars_uni($mybb->get_input('email2'));

(Lines 310 and 311)

And change it to:
$email = htmlspecialchars_uni(trim($mybb->get_input('email')));
$email2 = htmlspecialchars_uni(trim($mybb->get_input('email2')));


Note 1: Remeber to use a program like Notepad++ or similar to edit this file and save it without BOM.

Note 2: whenever you update your MyBB forum, if the "member.php" is updated, you'll have to change it again.

I did it, updated member.php, but the error keeps repeating.

I'm using these emails as test to register a new account:

"[email protected] "

"[email protected] .com"
Reply
#4
Solved: 1 Week, 3 Days, 13 Hours ago
(09-10-2019, 01:09 PM)NoRules Wrote:
$email = htmlspecialchars_uni($mybb->get_input('email'));
$email2 = htmlspecialchars_uni($mybb->get_input('email2'));

(Lines 310 and 311)

No, not these lines. They're for maintaining inputted values while displaying errors in a consecutive page, except passwords of course. Should do something before the data being sent to the datahandler, say before line 203:
	$userhandler->set_data($user);


(09-10-2019, 01:19 PM)ShadowOne Wrote:
"[email protected] .com"

This one is indeed an invalid email address.

I was assuming you're having this kind of email input:

"  [email protected]  "
Worth a try.
Reply
#5
Solved: 1 Week, 3 Days, 13 Hours ago
Ok,

I thought it was only at the begining and in the end.

Change it for this:
$email = htmlspecialchars_uni($mybb->get_input('email'));
$email = preg_replace('/\s+/', '', $email);
$email2 = htmlspecialchars_uni($mybb->get_input('email2'));
$email2 = preg_replace('/\s+/', '', $email2);
I don't answer questions about localhost forums or forums without URL, I'm not a seer.  Cool
Reply
#6
Solved: 1 Week, 3 Days, 13 Hours ago
(09-10-2019, 01:22 PM)noyle Wrote:
(09-10-2019, 01:09 PM)NoRules Wrote:
$email = htmlspecialchars_uni($mybb->get_input('email'));
$email2 = htmlspecialchars_uni($mybb->get_input('email2'));

(Lines 310 and 311)

No, not these lines. They're for maintaining inputted values while displaying errors in a consecutive page, except passwords of course. Should do something before the data being sent to the datahandler, say before line 203:
 $userhandler->set_data($user);


(09-10-2019, 01:19 PM)ShadowOne Wrote:
"[email protected] .com"

This one is indeed an invalid email address.

I was assuming you're having this kind of email input:

[email protected]  "

I'm convinced that most of my users are adding an extra space at end of their email

But considering that blank spaces are never valid inside an email, and that some smartphones have a keyboard with ".com" shortcut that may automatically add a blank space before adding it, I also took the case where blank space may be in the middle of email too.

(09-10-2019, 01:28 PM)NoRules Wrote: Ok,

I thought it was only at the begining and in the end.

Change it for this:
$email = htmlspecialchars_uni($mybb->get_input('email'));
$email = preg_replace('/\s+/', '', $email);
$email2 = htmlspecialchars_uni($mybb->get_input('email2'));
$email2 = preg_replace('/\s+/', '', $email2);

This one removed blank spaces, but only after sending the registration form and printing the error.

Users should hit the "submit" button again to register.

I'm looking for the point where registration is sent, to add the same code when registration is sent the first time.
Reply
#7
Solved: 1 Week, 3 Days, 13 Hours ago
(09-10-2019, 01:22 PM)noyle Wrote: No, not these lines. They're for maintaining inputted values while displaying errors in a consecutive page, except passwords of course. Should do something before the data being sent to the datahandler, say before line 203:
 $userhandler->set_data($user);

Yeah, right, need coffee....

Change 
"email" => $mybb->get_input('email'),
"email2" => $mybb->get_input('email2'),
Lines 167 and 168

to:
"email" => preg_replace('/\s+/', '', $mybb->get_input('email')),
"email2" => preg_replace('/\s+/', '', $mybb->get_input('email2')),
I don't answer questions about localhost forums or forums without URL, I'm not a seer.  Cool
Reply
#8
Solved: 1 Week, 3 Days, 13 Hours ago
(09-10-2019, 01:34 PM)NoRules Wrote:
(09-10-2019, 01:22 PM)noyle Wrote: No, not these lines. They're for maintaining inputted values while displaying errors in a consecutive page, except passwords of course. Should do something before the data being sent to the datahandler, say before line 203:
 $userhandler->set_data($user);

Yeah, right, need coffee....

Change 
"email" => $mybb->get_input('email'),
"email2" => $mybb->get_input('email2'),
Lines 167 and 168

to:
"email" => preg_replace('/\s+/', '', $mybb->get_input('email')),
"email2" => preg_replace('/\s+/', '', $mybb->get_input('email2')),

Solved! Thank you!!
Reply
#9
Solved: 1 Week, 3 Days, 13 Hours ago
In a current version of MyBB, the registration form will validate the email input at runtime. Your issue won't happen then.
Which version or theme are you running?

Without editing the hard PHP code, you can add an additional email validation at runtime to the registration form with JavaScript onfocusout():
<input ... email ... onfocusout="validateMail()">
<input ... email2 ... onfocusout="compareMail()">

When the address is typed in and the user switches to the next input field a simple JavaScript function validates the first input... and checks the second one as well. A wrong input may change the text-color to red or change the CSS class to input.error for example. The user alerted in this moment and not after submitting the form.

A piece of JS code can be put anywhere within the template.
Search for any simple JS email validation snippet and you'll find a bunch.

[ExiTuS]
Reply
#10
Solved: 1 Week, 3 Days, 13 Hours ago
(09-10-2019, 01:53 PM)[ExiTuS] Wrote: In a current version of MyBB, the registration form will validate the email input at runtime. Your issue won't happen then.
Which version or theme are you running?

Without editing the hard PHP code, you can add an additional email validation at runtime to the registration form with JavaScript onfocusout():
<input ... email ... onfocusout="validateMail()">
<input ... email2 ... onfocusout="compareMail()">

When the address is typed in and the user switches to the next input field a simple JavaScript function validates the first input... and checks the second one as well. A wrong input may change the text-color to red or change the CSS class to input.error for example. The user alerted in this moment and not after submitting the form.

A piece of JS code can be put anywhere within the template.
Search for any simple JS email validation snippet and you'll find a bunch.

[ExiTuS]

Are you sure?
I'm on 1.8.21 (just upgraded) and using default theme with few style edits (just colors)
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)