• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Strip space from email address

Strip space from email address 3 years 4 months ago #41747

  • dlm
  • dlm's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 71
Hi there,

How can I strip the email-field from a space that is typed, for example at the end of the email address.
Before the validation rule is executed. (because that is the reason why I get an error)

Kind regards
The administrator has disabled public write access.

Strip space from email address 3 years 4 months ago #41753

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
I'd use the PHP trim function in 'script called before form is validated' section, the following will remove whitespace from both ends of a variable
Explanation here

if the spaces are typed in the middle of the email as well as the end you could use str_replace
$str = ' This is a simple piece of text. ';
$new_str = str_replace(' ', '', $str);
echo $new_str; // Outputs: Thisisasimplepieceoftext.
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
The following user(s) said Thank You: dlm

Strip space from email address 2 years 8 months ago #42162

  • bob3
  • bob3's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
Hi @iceferret -

What code would I use to apply the PHP trim function to the Email field only?
Robert Clinton
Owner

CAPE COD WEB DEVELOPERS
Harwich, Ma
The administrator has disabled public write access.

Strip space from email address 2 years 8 months ago #42163

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
I would do the following
$str = $_POST['form']['mail'];
$result = trim($str);
$_POST['form']['mail'] = $result;
echo $_POST['form']['mail'];

Using trim() removes spaces from either end, if you are only after removing characters from one end or the other there is ltrim() and rtrim() as well
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
The following user(s) said Thank You: bob3

Strip space from email address 2 years 8 months ago #42164

  • bob3
  • bob3's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
So if the field name is "E mail" the code would be...
$str = $_POST['form']['E mail'];
$result = trim($str);
$_POST['form']['E mail'] = $result;
echo $_POST['form']['E mail'];
___________________________________
THANKS ICEFERRET!
Robert Clinton
Owner

CAPE COD WEB DEVELOPERS
Harwich, Ma
Last Edit: 2 years 8 months ago by bob3.
The administrator has disabled public write access.

Strip space from email address 2 years 8 months ago #42165

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
Yep, I forgot to mention that didn't I.....doh! Change the email field name to 'E_mail' though to avoid potential problems. Unless I miss the mark variables should not contain spaces
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 2 years 8 months ago by iceferret.
The administrator has disabled public write access.
The following user(s) said Thank You: bob3
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!