Tuesday, August 21, 2007

Custom Forms in SharePoint 2007

Hi!

This post will be about creating a custom form for a list. The need to do this arose when a customer of mine wanted a pair of dynamic dropdown lists where this was the first step in the solution.

This information has been taken from SharePointExpert and from Kristian Kalsing's blogpost about custom forms which are both excellent blogs with many good articles.

First off, open SharePoint Designer (SPD) and open the web site of interest.

Next, navigate to the list which is to have the custom form and find the folder Forms inside the list. Inside this folder resides all the default forms that the library will use for any given situation such as uploading, checking in or editing the properties of a document.

Now, open the form that you whish to make a customized version of. Notice that the form only contains a single webpart, the ListFormWebPart.

This webpart does not allow us to do anything useful and therefore we are going to remove it. But before you do this, make a copy of the form you opened and give it a good name. In my case, with my customer, it was the EditForm.aspx that was copied to EditForm2.aspx.

When the ListFormWebPart has been removed, a new control is going to be inserted. Goto Insert -> SharePoint Control -> Custom List Form. This will bring up a dialog box where the list, content type and operation type can be selected. Once you have selected all of these, click the Ok button.

As can be seen, I have chosen to make a new Edit form for my Shared Document which uses the Document content type. Now, all metadata fields will appear in a table which you can edit and modify as you whish. Be careful when removing fields that you don't want the users to see so that the fields are not required.

When you are done, go to a browser and navigate to the list that has the customized form and try it out. This can be done in many ways, the easiest that I have found is to go to the original form and then write in your name instead of the original form name in the adress field.

After this comes the tricky part, getting the form to actually appear as the default form for the operation.

To be able to do this go to the list in SharePoint Designer and right click. Choose Properties and then go to the tab named Supporting Files. Here you will be able to upload different forms than the default SharePoint forms, such as the form you have just created.

Upload you new form. This is not end of it though. When hitting the Ok button the error "the page you have selected does not contain a reference to the correct sharepoint list..." will appear. To get rid of this error you have to go back to the original form and copy the whole WebPartZone tag with all its content to the new form. This will give you two web part zones in your form and both have the same Id. Rename your webpart zone with the DataListWebPart to something else.

Now go down into the ListFormWebPart, that is the web part you just copied into your customized form, and set the IsVisible tag to false.

Now the new form will be the default form for the specified action.

Good luck!

 

//Sebastian

Posted by Zeb at 17:27:06 | Permanent Link | Comments (9) |
Comments
1 - Very usefull! Great post!

Gustaf Westerlund
 (Comment this)

Written by: Anonymous at 2007/08/22 - 10:23:36
2 - Do you know how to deploy this custom form that are created to another environment like production. Do we require to have sharepoint designer on the production also and do we need to repeat custom form creation again?
 (Comment this)

Written by: Sameer at 2007/09/07 - 18:06:03
profile
3 - Hi Sameer!

To deploy this solution you will have to do all the work against the production server again, if you haven't already done it towards that server.
On the other hand, you do not have to have SharePoint Designer installed on the server. It is enough if you have SharePoint Designer installed on a workstation and have access to the production server to be able to do all the work you need.

Best regards

Sebastian (Comment this)

Written by: Zeb at 2007/09/10 - 09:09:49
4 - Excellent article Zeb!!!!!!!!!

Is it possible to make this customized edit form the default for all document lists within a site without having to go each document list and changing the "supporting files" to the custom form like you mentioned?

Thanks.
Rohan (Comment this)

Written by: Anonymous at 2007/10/12 - 22:50:57
5 - Hi Zeb,

Excellent artciel!!!In your article, you manually assign the custom form to a single document list. Is it possible to assign the custom form to all the document lists within a site?

Thanks.
Raj (Comment this)

Written by: Anonymous at 2007/10/15 - 15:40:50
profile
6 - Hi Rohan!

It is possible to save a list, or in this case a document library, as a template and to reuse this template in different sites in your site collection.
I have not tried this out for myself yet, but do not see any problems with the behaviour of the list in this scenario.

But if you would like to push out your changes to other list that already exist, then my answer is that it is not possible today.

//Sebastian (Comment this)

Written by: Zeb at 2007/10/16 - 09:11:51 in reply to: 4
profile
7 - Hi Raj!

I am not aware of any solution that will implement the custom form on all lists in a site. but you might save the customized list as a template and then use the template when creating new lists.

//Sebastian (Comment this)

Written by: Zeb at 2007/10/16 - 09:14:25 in reply to: 5
Write a comment