Ask a question

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all Q&As

In this Bubble video tutorial I'm going to show you how to split a full name into a first name and the last name and how to use database triggers to ensure that you're never caught out or you never miss out on a user. Updating their full name and then not updating the first name and last name fields.

Create a simple registration form in Bubble

So I have a quick form here, I'm going to turn this into a registration form by adding a workflow onto the registration button. So account sign the user up and then email password. And I'm going to have a new field called Full Name.

And I've got two full name fields because I'm going to demonstrate after this how to update Full Name and First Name and Last Name and just do it really simply and quickly. Cut down on the number of workflows that you need to do this.

Create a database trigger

So I then go and this is only available on pay plans for Bubble. I go and create a database trigger and the database trigger allows you to run a workflow when information in your database is changed. So I would call this update user Name and the type is User.

App optimization

And then if I don't fill in this section here and you can read all about this in the Bubble documentation, database triggers are immensely useful. It's really worth you getting used to them and building them into your app. It basically means that you don't have to duplicate although the workflows. Imagine you wanted to update your user's names on one part of the app but you also wanted to update them on another part. You'd end up duplicating your process to ensure that your full name and your last name and your first name are all in sync.

Database triggers just do it automatically in the background and if you don't fill in this section here only when it's going to run every single time there's a change to the user which is just not great for your app's optimization because it's running it too many times. Even though we're doing a relatively small process, you want to build your app with optimization in mind.

So I say when current user's full name is not user now Full Name and so that's saying when the user's full name changes, run this workflow. So then I go to make changes to current user and I go I like the naming convention like this because then it just groups it all together so that's the first name and then that's the last name.

How to split full name with Bubble

Okay and how do I split it? So I go user now Full Name and then I go split by space and then I say show only the first item and then last name I'll go user now. And this isn't going to be perfect. I mean there's lots that you can get into here. For example the fact that the whole first name last name convention is not used globally which will account for here.

Imagine if someone has got like a Mac Donald but they put a space between the Mac and the Donald on their last name. So what we'll do is we'll say full name split by space and then we'll say items from two. And we'll do that because we're basically saying that anything that isn't the first name is going to be put into last name.

Yeah, and just to be sure we will add in the join with because I think by default Bubble uses a comma but we're going to use a space. So that should, even if the person has put in three different words as their name, it's going to take the first name as the first word and any following words it's going to put them as the last name. It's going to put a space between them and that will run automatically in the back end of the workflow.

So let's go back to our page of names and let's preview. So I'm going to put in my name, Matt Blake and my email address and password and then hit register. Okay. And then so we can see if that's worked, I'm going to add in some extra fields here. So I'll say current user, full name. Then a new line. I'll put current user, first name, new line, current user, last name. Let's see if that's worked. So the registration flow has logged me in and because I built this page quickly in the fixed layout, I don't think it's showing all the text. Let's try again.

There we go. So you can see that it split out all the different parts. Now what if I wanted to update it? Well this is the beauty of back end workflows and using database triggers because all I need to do is update the full name. So account make changes to user full name equals full name field two.

So let's go for Peter Parker and I click update and you'll see that there's a brief delay but that's the database trigger. So you saw that this updated first. That's because that's our workflow attached to here. And then when Bubble detects that full name has changed to the user it will update it for the first name and the last name.

Okay you can do any number of combinations of this. You could even like reverse engineer this so that you input as is often the case, you might instead on your registration form have a first name and a last name. But you might have a part of the app where you want to display the full name and you always want to display the full name. And so you could do this the opposite way around. You could store the first name and the last name and have a database trigger that combines them into the full name. Anyway, there we have it.

That is a quick overview of using split by and using database triggers to handle full names, first names and last names in Bubble.

Latest videos

lock