Customize the NewForm
Have you ever wanted to change the fields presented in a form when you create
a new announcement or task for your SharePoint team site? Do you wish you
could remove a field or two in order to keep someone from changing important
metadata once a document has been uploaded into your library? Perhaps you
would simply like to expose different fields to different users when editing
information in a document library or list. Well, follow along with me now because
I’m going to take you on a short journey and show you how to do just these very
things.
Hello, my name is Daniel A. Galant and for the past several months I have been
employed as an instructor with Mindsharp, the SharePoint people. One of the
questions that keeps coming up in our sessions is “How can I change the default
new item or edit forms to present only the data fields I want certain user groups
to be able to modify?” To begin, let’s take a look at just what it is we are trying to
change.
When you want to enter a new item into, let’s say, your announcements list,
SharePoint calls upon the NewForm.aspx page for that list, in this case,
announcements. The page contains a customized List Form Web Part that
displays default columns associated with the Announcements list properties. The
New Item form cannot be edited within the browser, so in order for us to
accomplish what we want to do, we will need to call upon our trusted companion
tool, SharePoint Designer 2007.
To begin our modification journey let’s start by opening up a team site in the
browser and taking a look at the default New Item page that we have to work
with. Figure 1 shows the home page for the Technical issues team site that we
will be modifying.
Figure 1: Technical Issues home page
By selecting the Add new announcement link we are presented with the
standard Announcements: New Item page (Figure 2) for adding
announcements to our list. Note the columns that are currently available for data
entry: Title, body and Expires.
Figure 2: Announcements: New Item page
To modify this page we must open it in SharePoint Designer 2007 and then add
a new custom List Form Web Part that displays only the fields that we wish our
users to modify. Start Designer and then connect to the website that contains the
list whose form you wish to modify, in our case that would be the Technical
Issues Team site as shown in Figure 3.
Figure 3: Technical Issues site loaded into Designer 2007
Next we need to open up the relevant NewForm.aspx page. In the Folder List
expand Lists and then expand the list you want to work with. Again, we are
going to modify the Announcements list so expand Announcements and select
NewForm.aspx.
Figure 4: NewForm.aspx in the Announcements list
As you can see in Figure 5, the Announcements: New Item page contains a
customized List Form Web Part that will display the fields we noted earlier when
we opened the page in the browser. While we can edit the properties of this
particular web part, we cannot edit the contents, nor do we want to delete the
web part from the page as this can break the NewForm.aspx page and cause it
to error out when you try to actually use it in your site. Stick with me because we
are going to cover how to deal with this as we go though this tutorial. For now,
we want to add some space below the current web part so that we may add our
own custom list form to do with as we like.
Figure 5: The default NewForm.aspx page
Select the area just below the current list form and press Enter twice to give
yourself some room to work with. Next, to add our custom list form go to your tool
bar and select Insert>SharePoint Controls>Custom List Form.. as shown in
Figure 6.
Figure 6: Add a new Custom List Form
Selecting the Custom List Form will bring up the List or Document Library
Form dialog shown in Figure 7 where we need to choose which list we are tying
this new web part to as well as the type of form we want to create. In our
example we are keeping the default Announcements list since we are creating a
new Announcements form as well as selecting the New item form radio button
because we want to use this web part to create new announcements for our site.
If we were going to modify the web part for a different document library or list
within our site we would need to choose that library or list from the drop down
menu. If instead of creating a new item, we wanted to use this form to edit an
already existing item; we would select the Edit item form radio button instead.
Figure 7: List or document library selection dialog
When finished you should have your new list form web part as displayed in
Figure 8.
Figure 8: Newly added List Form web part
As mentioned earlier, the form we are using is pulling its data fields from the
columns that are defined in the list or library that we are connecting the web part
with. What if we want to create our own columns or collect information about
items that are not currently part of the list or library? To do this we would need to
add additional columns from already existing Site columns or simply create our
own to suit our needs. To accomplish this task we must venture into the settings
of the list or library that contain the items we want to collect or modify data from.
We’ll start by selecting the View All Site Content link at the top of our Quick
Launch menu at the left hand side of the browser window. This will bring up the
All Site Content screen as seen in Figure 9. Next we must select the list we are
working with, in our case that would still be Announcements.
Figure 9: The All Site Content page
Once you are in the list or library that you want to add information to, select the
Settings menu and then select List Settings, (Figure 10).
Figure 10: List Settings menu option
On the settings page for your list or library you will see a section titled Columns,
(Figure 11). It is here that we can add columns from the already defined site
columns in SharePoint or create a new column to collect whatever data we need
for the items in our list.
Figure 11: Create or add new columns section
When you have defined the metadata types that you wish to collect on your list
items, we need to make those columns available in our new List Form Web part.
To do that, we’ll go back to SharePoint Designer 2007 and add the form
elements into our new form.
In the Toolbox task pane you’ll notice a section labeled SharePoint Controls
(Figure 12). If the Toolbox is not visible in your Designer, go to the Task Panes
menu item and select Toolbox. Expand the SharePoint Controls and you’ll see
the various elements that can be inserted into your form to allow you to collect
the data that is relevant to your list items. These elements directly map to the
column data types that are defined when you add or create a new column in any
library or list within SharePoint.
Figure 12: SharePoint Controls in the Toolbox task pane
Select the data view control that maps to the type of field whose data you wish to
collect and drag it from the toolbox and drop it into your new list form. This will
bring up a control dialog in which you will map the control to the column in your
list whose data you are interested in. You’ll notice in Figure 13 that we dropped a
text box into our form and we are going to map it to the Modified By field in our
Announcements list.
Figure 13: Mapping a list field to a data view control
Next we merely give our new control the proper label, (Figure 14) and then save
our new NewForm.aspx page.
Figure 14: Adding the label for our control
Since we are modifying the default page you will receive a warning (Figure 15)
that the page is being altered from the site definition. Select Yes to save the
changes.
Figure 15: Site definition warning dialog
Now we can view our new New Item page in the browser and see just what we
have done. As you can see in Figure 16 there are now two list form web parts on
the page; our original web part with the default configuration of fields, and our
new web part with its modified content.
Figure 16: New Item page with two list forms
Since we want to present only a single form for our users to fill out, with only the
items we have selected for them to modify, we must hide the original web part on
the page. To accomplish this we again return to Designer 2007 and the
NewForm.aspx page we have been working with.
Select the original ListFormWebPart and hide it by right-clicking and selecting
Web Part Properties from the popup menu. (Figure 17)
Figure 17: Selecting Web Part Properties popup
In the Announcements properties expand Layout and check the box for Hidden
(Figure 18). Again, we don’t want to delete the default web part since this can
break the page and cause it to error when trying to load within SharePoint.
Remember to save the new page.
Figure 18: Hiding the default Announcements web part
We now have our Announcements: New Item page that only displays the
elements that we want to expose to our users as seen in Figure 19.
Figure 19: The new Announcements: New Item page
Using the principles shown here you can create a form to display any of the
content columns that are associated with your lists and libraries in your
SharePoint deployment. But what about exposing different columns to different
sets of users? By applying what we have learned here you can create separate
web parts that expose only the columns you want exposed for each set of users
and then apply audience filtering to make them accessible to the proper groups.
So what about removing elements from the Edit Item form so that metadata isn’t
improperly changed when a user edits the properties of an existing document?
Let’s take a quick look at the Edit item page for a document library where content
types are enabled. Notice in Figure 20 in our Problem Reports library App Crash
document properties there is a field to select the content type that is associated
with this document. A misinformed user could potentially change the content type
associated with this document and thereby change the metadata or even
workflow’s attached with this document type.
Figure 20: Edit Item page showing Content Type selection box
To prevent this situation for occurring we need to modify the default
EditForm.aspx page that is associated with this document library. To do that we
need to use Designer, just as we did when modifying the NewForm.aspx page
earlier.
Start by connecting to the site that contains the document library (our Technical
issues site) and then locate the library you want to work with (Problem Reports in
our case). Expand the library and you will see the associated forms as shown in
Figure 21. This time we want to modify the EditForm.aspx page so open it with
Designer.
Figure 21: Selecting the library to work with
Now just as we did with our previous NewForm.aspx page we need to add a new
list form web part to the page and hide the existing default web part from our
users. This time, however, when we insert our new web part we must be sure to
connect it with the proper library (Problem Reports) as shown in Figure 22 and
then select the proper form type (Edit item form) that we are creating as shown in
Figure 23.
Figure 22: Connecting the form to the proper library
Figure 23: Configuring the List Form Web Part
From there it is simply a matter of configuring the field types, adding the proper
SharePoint controls and saving our page. Figure 24 shows the modified Problem
Reports library Edit Item page without a content type selection box.
Figure 24: Edit Item page without the Content Type selection box
So there you have it. You can now modify your default forms to display just the
fields you want them to while hiding the ones you need to.