Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So we have seen how to put a Number field and quite honestly, it's very easy. You can look at all the different options of decimal points, float versus decimal as you like. But for now we are going to delete that Temp Content type and go back to our Person Content type that we'll use throughout this course. To delete this Content type, we go back up to Administer > Content > Content types and just hit the delete link right there and click on Delete. But if you want to use a field type besides Text and Number, you are in luck because the drupal.org website has many to choose from. Right now in our project we have only one custom content type called Person, which is only two fields, a first and last name. And both of those are simple text fields. We are going to get a Module that will let us give our people one additional piece of information, a date of birth.
The Module that does this is called, amusingly enough, Date. We are starting to get into some more complicated modules where one module depends on another and sometimes requires you to add information that wasn't in the system before. That's okay, if the module is well written as these two are, Drupal will warn you when it needs information. So without fear, we'll forge on and we'll add what's needed as we go. First we'll get that date module. Go to drupal.org/project/date, scroll down and download the version that we are going to use. We have already downloaded and installed the date module. Now we'll go to turn it on. As always go to Administer, Site building, and Modules. And scroll down. You will see a new section here called Date/Time. The very core of the Date module is this Date, one right here, the rest of these do a lot of interesting things and I'll explain what some of them do but for now we are only going to turn on one. You will note however, we'll be told to turn on others as needed. Scroll to the bottom and click Save configuration.
See, it tells us that we need to turn on two more Modules to install Date. That's something very useful that well written Modules will do. They will force you to turn on certain other Modules that need to be enabled. Of course we'll say Continue. And we are back here. I would like to show you one other part of the Date Module before I go on, so we'll scroll down to that field group. One of the Modules it installs is called Date Tools. When you are actually building a site, it's a lot easier to turn on that Module and use the Date wizard that's built into it. Not only does it setup the Content type properly with a date field, it also creates some really nice calendar based views using that Content type. But I have decided to specifically to not use that tool so that you can see how to setup such CCK fields manually. I'll show you the interface for the Date Tools Module in the video Planning with a Calendar Module.
Now we want to go back and edit that Person Content type, you are going to notice something as we go back there. We are going to get a warning message that tells us we need to add some information because the Date Module requires it. But let's go there. Go up to Administer, up, and there it is. One or more problems were detected Check the status report. Click on the link. The Date Module requires that you set the time zone that you are using. Drupal usually doesn't require that, so all of a sudden we have to do that. Well, that's easy enough. They give us a link to do so. Since I'm recording this in Ventura, California. I'm going to down to the America/Los_Angeles selection. Close enough. Look at some of the other options. Yeah, First day is Sunday. That's fine. Users can set their own time zones. I'm fine with that.
And say Save configuration. Good, now we can continue on to Administer, Content management and Content types. Once we are there, we are going to go into the Person Content type and manage its fields. Once we are here, we are going to date of birth for this person. We go down to our new field, add Date of birth as the label, date_of_birth. Select our Field type and here you will notice three new options, Date, Datestamp, and Datetime. These have some differences in the UNIX world and if you would like some documentation on that you can find it on drupal.org and also in some UNIX documentation.
But for us we'll just choose Date and we'll leave it as a Select List. The other option is Text Field but that introduces the possibility of more errors from the users, so Select List it is. Scroll down and as usual click Save. On this page there are many, many options and we won't have time to go into them all, I'll just mention a couple. The first is that Dates can actually have from dates and to dates and several of the options on this page reflect that, so you could, for example have a multi-day event. In our case, it's a date of birth, so we won't be using two dates. We'll just have the to date be the same as the from date as you can see in this setting.
Scrolling down a little further, I would like to make one more change, this Years back and forward. Since we are using the Select List option, we'll only see a certain number of options to prevent that list from being infinitely long. We are dealing with a date of birth however, so we know that nobody is going to be born in the future in the way that we are using this in the database. So I'll say 0 there, but they could be born as much as 100 years back, so I'll say 100 there. Scroll down further, I see another reference here to, to date. Once again, we'll never have a time when someone was born one day to another.
In Granularity, we are not going to record the Hour and Minute that someone was born. So we can undo that by simply clicking on the Year then to select Month or Day, we can hold down Shift, on the Mac Command or on the PC Ctrl to select multiple ones. Scroll down a little further, as it happens because we are not using Hour or Minute, the time zone handling doesn't matter, we could just save now and then we would get an error. I happen to know about the error, so I'll say No time zone conversion, and save. As usual to make it look good in the form, I'm going to drag this up underneath the Personal and Family name, scroll down and save. Now let's take a look at what that actually looks like when you are editing a person. We'll go back to our front page where we see the only person that we have in this database, Tom de Nada. I click on it and we see all that blah, blah text we added earlier.
First thing I'm going to do is Edit it and get rid of all of that. Just select it all and hit Delete and scroll back up. Back at the top of the page you see exactly what you would expect, our Year, Month, and Day. Let's say that he is born in 1968, now you could scroll down through all of this but here is a little trick. When the field is highlighted as it is, you can usually just type in 1968 and it will jump to the correct one. That's true in most browsers but maybe not all. We'll say that he is born on April 16th and scroll down and Save.
Now if we return to our front page, we see exactly what we would expect, the name, the date of birth, and the body. You might remember from another video about cleaning up our display and that's actually fairly easy to do. We just go back to the Content type. Administer, Content management, and Content types, and then next to the Person Content type, click on Edit and Display fields. Once again, we can hide that label if we like but I think we'll actually leave it. We'll keep it Inline however, and save it.
As a side note, I want to mention we are only recording a single date or at least a date for a single event with a from and a to. That's not the same as what people usually think of a birthday, which repeats every year. As it turns out recording a birthday is actually somewhat more difficult to implement in Drupal at the moment using CCK fields. Instead most people use a completely different Module called birthdays, at drupal.org/project/birthdays. Just a recap, here are the URLs for Modules mentioned in this video. You will find many, many more Modules that work with CCK in some way at drupal.org. To find them, go to drupal.org, click on Modules and then take a look down here.
You will see the Content Construction Kit category, click on it, and again there are dozens if not hundreds available. Even if you filter it to only be for Drupal 6, many of these let you add new and even unusual kinds of fields to Content types such as bar codes, media files, currency, validated postal addresses, and many more. Others extend CCK's functionality with such things as per field security and conditional fields that appear only if certain calculations check out. If you plan to do anything on your site beyond text and graphics, I definitely recommend spending some time perusing this category and a few hours learning the features of each Module of interest.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.