Redirect from default form to custom form

Posted: December 1, 2009 in Custom Form, javascript

Whenever you create a custom form for a list, we always go for creating a Custom List form in SharePoint designer. Of course using this method, you will get the querystring values what you get in the default forms. But what if you want to add more querystring parameters to your custom form page?

One way is to create a webpart and place in the default form, which will redirect to your custom form by adding required querystring parameters. But this is little complex. So I used a JavaScript which you can place in a Content Editor Webpart in the default form.

<script> 

function getQuerystring(key, default_)
{
                if (default_==null) default_=””; 
                key = key.replace(/[\[]/,”\\\[“).replace(/[\]]/,\\\]);
                var regex = new RegExp(“[\\?&]”+key+”=([^&#]*)”);
                var qs = regex.exec(window.location.href);
                if(qs == null)
                                return default_;
                else
                                return qs[1];
}

function doRedirect()
{
                var ID_value = getQuerystring(‘ID’);
    window.location.replace( ‘/sites/CLegal/LegalOpinions/Shared%20Documents/LegalOpinionForm.aspx?Mode=Edit&ItemID=’ + ID_value  );
}

doRedirect();

</script>

Here in the script getQuerystring method gives you the current page’s querystring values and I have added the “Mode” querystring parameter. Never forget to change the parameter name ID to something else in your custom form, since it will give you error in displaying the items

Advertisements
Comments
  1. You actually make it seem so easy with your presentation but I find
    this topic to be actually something which I think I would never understand.
    It seems too complex and very broad for me. I am looking forward for your next post,
    I’ll try to get the hang of it!

  2. I do not even know how I ended up here, but I thought this post was great.
    I do not know who you are but certainly you are going to a famous blogger if you aren’t already 😉 Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s