25 March 2011

Create a custom list form in SharePoint

This time I'll explain how to create a custom form in SharePoint 2007.

The same example I will explain about "new item" (New Form), you can intuitively, in the same way, build a form of editing (Edit Form) and a form of view item (Display Form).
One reason to create a custom form is redesigned, another reason is the function LockDown Feature form STSADM - "Lock Down Feature" is a function for an Anonymous Site as I explained previously.
We Knows the "New Form" that comes out of the box in SharePoint (See example screen "New Item" in MOSS 2007 picture below). We want to build a new form. The form that will be a new design and located in different library (Not in Lists library) - that the Lock Down Feature will not disturb us to work.

First we'll create a copy of the original NewForm.aspx to Pages library . Now will change the name (preferably - not required). You can of course create a new aspx form in SharePoint Designer. In my way, I save a step or two.

Opens the file, go to PlaceHolderMain and return it to "Default Master's Content." Then we define it as a Custom.

Now in PlaceHolderMain create "Custom List Form." (In SPD: Insert -> SharePoint Controls -> Custom List Form).

Now select the list and the kind of form we want (in this case "New Item Form").

Now we can go crazy with the design of the form and format of the XSL.

At the end of course do not forget to "Check In" the form.

To link the new form went over the list in SPD to the properties. In Tab "Supporting Files" selected the new file we created.

We can see already on the list when we see the redirect is performed automatically.

And the beautiful design of the list that I built.
To change from "New Form" to "Edit From" or "Display From" you will nedd the replace the "new" on ControlMode from ControlMode="New" to ControlMode="Edit" at the SharePoint:FormField tag.

:)

12 March 2011

Add Value from QueryString to SharePoint List Form

This time I will demonstrate how to add content to the field directly to the url path (QueryString) to SharePoint List Form (Only for MOSS 2007).




Step one, open form in SharePoint Designer (NewForm.aspx, EditForm.aspx). (You need to Do backup to the form before).



Step two, add the following JavaScript code, where you can open a script tag (See an example where I added the code to SPD in the image attached)


if (typeof(_spBodyOnLoadFunctionNames) != "undefined") 
{
 if (_spBodyOnLoadFunctionNames != null) 
 {
         _spBodyOnLoadFunctionNames.push("SetMyField");
 }
 else
 {
         window.onload = SetMyField();
 }
}
else
{
 window.onload = SetMyField ();
}
function SetMyField()
{
 var MyField = getURLParam("MyField");
 var inputs = document.getElementsByTagName("INPUT");
 for (var i = 0; i < inputs.length-1; i++)   
 {
         if (inputs[i].title == "My Field")
         {
                inputs[i].value = MyField;            
                inputs[i].readOnly = true;
                break;
         }
 }
}
function getURLParam(strParamName)
{
         var strReturn = "";
         var strHref = window.location.href;
         if ( strHref.indexOf("?") > -1 )
         {
                var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
                var aQueryString = strQueryString.split("&");
                for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
                {
                        if ( aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
                        {
                        var aParam = aQueryString[iParam].split("=");
                        strReturn = aParam[1];
                        break;
                        }
                }
         }
         return unescape(strReturn);
} 
String.prototype.endsWith = function(str)
{
    return this.lastIndexOf(str) + str.length == this.length;

}



In row- if (inputs [i]. title == "My Field"), should change to your field.

Roi