2

I have a list and when i try to add a new item and save it it redirects me to the list but instead I want to redirect me to the Google.com

I have opened the NewForm.aspx in SharePoint Designer and looked for Save button or any url related to Save Button but I found nothing there.

Thanks

6

You can add Script Editor web part to the NewForm.aspx page. Then add custom JavaScript which will first remove the onclick event of the Save button and then add the click event to the same button with new redirection logic. Example code from Custom redirect after creating a new Sharepoint Item

$(document).ready(function() {

    var button = $("input[id$=SaveItem]");
    // change redirection behavior
        button.removeAttr("onclick");
        button.click(function() {
            var elementName = $(this).attr("name");
            var aspForm = $("form[name=aspnetForm]");
            var oldPostbackUrl = aspForm.get(0).action;
            var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
            var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "MyRedirectionDestination.aspx");

            if (!PreSaveItem()) return false;
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
        });

});
  • I am getting the following error Uncaught TypeError: Cannot read property 'action' of undefined, I have added jquery-1.8.0 library – Iamnderon Aug 24 '16 at 7:42
2

A twist on Nadeem's answer for those who can't do Javascript

You can use the Source parameter in the URL to redirect to another page, by default it will point back to the AllItems View

You can use your own value:

.../NewForm.aspx?Source=www.google.com

Open your current NewForm, and inspect it yourself
it will look a bit garbled because all special characters are URLEncoded with %xx notation

Now make up you own URL with source= and use that on a page where you want to link to the Form

If you want to change the the New Item button on the View you do have to use JavaScript to change the href setting
Apart from that its just creating your own hyperlink on pages

Nadeems cool answer uses JavaScript to change that Source= setting

  • Danny, I cannot find any way to use my own value, where should I put .../NewForm.aspx?Source=www.google.com I have opened my NewForm with designer but I can't figure out where to put it – Iamnderon Aug 24 '16 at 8:23
  • Not on the Form, only on another Page where you have full control over the HREF link TO the Form page – Danny '365CSI' Engelman Aug 24 '16 at 8:25
  • Danny I want to redirect me in the google and where should I change my URL to add source= I can't get your point – Iamnderon Aug 26 '16 at 9:17
0

You can not do it from NewForm.aspx. The reason is we do not have any control on the code that is saving item. So you can create a content editor web part for doing this.

  1. Create a custom from using HTML
  2. Save Item using JSOM or REST API
  3. After saving the item, redirect to google.

You can take REST API help from my article!

CRUD Operation to List Using SharePoint 2013 Rest API

  • do you provide any code sample because I am new to sharepoint? – Iamnderon Aug 20 '16 at 14:48
  • I have added an REST API reference in my answer – Atish Dipongkor - MVP Aug 20 '16 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.