Here is the scenario: you have a list or document library and your users have requested special changes to the out-of-the-box display, new or edit forms. Perhaps they want a few extra Web Parts added, or you need to make another form that will serve the purpose of being a print-friendly version of the existing form, remove default master page elements, or add item specific functionality. Here is what's involved...
Before we begin, I am assuming you're creating a new solution, so we start with defining a list or document library that our users will end up using. We'll use a custom list as our example. If you take a look at the definition of the custom list from the 12 hive you will see schema.xml which defines all of the fields and views for this list and the CustomList.xml file defining the type, image, and other list properties. The easiest thing to do is to copy the existing list and customize the schema.xml and the template definition file to match your needs. Now we're ready to modify the look and functionality of the default form. In your schema.xml at the very bottom of the definition find the following section:
<Forms> <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /></Forms> </Forms>
This section defines standard out-of-the-box forms. We'll add another line right after NewForm that will look like this:
<Form Type="DisplayForm" Url="PrintForm.aspx" SetupPath="pages\MyTemplates\form.aspx" WebPartZoneID="Main" />
What we defined above is that our form will:
- Behave like a display form — that is all of the fields will be read only labels, etc.
- Will have our custom name of PrintForm.aspx
- Will use pages\MyTemplates\form.aspx as a template, which we define next
If you take a look at 12 hive/TEMPLATE/Pages you will find form.aspx — a file which display, new, and edit forms look up to conform to the defined style. Create a new folder in your 12 hive/TEMPLATE/Pages called MyTemplates and copy the form.aspx from the parent to your new folder. In my example, since I had to create a printer-friendly version of the display form, I removed everything from my new form.aspx and ended up with this:
<asp:Content ID="Content1? ContentPlaceHolderId="PlaceHolderPageTitle" runat="server"> <SharePoint:ListFormPageTitle ID="ListFormPageTitle" runat="server"/> </asp:Content> <asp:Content ID="Content2? ContentPlaceHolderId="PlaceHolderMain" runat="server"> <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main" /> </asp:Content>
The last step is not required unless you want to change the look of your new form master page. Since my goal was a printer-friendly view – I had to make my master page as simple as possible, below is the example of the body:
<BODY> <form runat="server"> <WebPartPages:SPWebPartManager id="m" runat="Server"/> <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server"> </asp:ContentPlaceHolder> </form> </BODY>
Once my master page and list provisioning features were activated, my new display form was accessible under MyList/Forms/PrintForm.aspx as I defined it in my schema.xml
Hope this helps in your form customizations!