• 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: Split fullname into First Name and Last Name

Split fullname into First Name and Last Name 4 years 11 months ago #40134

  • contact13
  • contact13's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 30
  • Thank you received: 5
Hello! I have a form where I'm pulling in the name of a user by {global:fullname} and it is returning their name correctly. However, I need to split up the first and last name into two separate fields to map it to a Google Sheet (where Column A = First Name and Column B = Last Name). Not sure how to separate that out...

Because of my registration process, each user does have a first and last name, separated by a space. I'm just not good enough with the code to separate them.

I'm open to using JS to set hidden fields based on the space in the fullname, or using any other method to do it during the mapping.

Any ideas?
The administrator has disabled public write access.

Split fullname into First Name and Last Name 4 years 11 months ago #40136

  • contact13
  • contact13's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 30
  • Thank you received: 5
If anyone is looking for this, I figured out a way to do this. See below. Note you can return either $firstname or $lastname for the appropriate field.
//<code>
$loggedIn;
$userName;
$user =& JFactory::getUser();
if (!$user->guest) {
  $userName = $user->name;
}
 
$parts = explode(" ", $userName);
$lastname = array_pop($parts);
$firstname = implode(" ", $parts);
 
return $firstname;
 
//</code>
The administrator has disabled public write access.
  • 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!