0

I have created one custom new form of a list in which I want to redirect the user to other page after saving item.

I have placed <input> button to save the item and set the __redirect attribute to my custom page in Pages library. My site url is like, <sitecollection>/Pages/Page.aspx for e.x., http://xxx/sites/web/Pages/Page.aspx.

My HTML code in CustomNewForm.aspx is:

<input type="button"
       value="Save"
       onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/Pages/Test.aspx}')}" />

But when press save button it redirects me to http://xxx/Pages/Test.aspx rather than http://<sitecollection/site/web/Pages/Test.aspx

What should I do?

2

try using the below script on NewForm.aspx

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript">function PreSaveAction() {
    var URL = location.pathname.replace('NewForm.aspx', 'DispForm.aspx');
    if (GetUrlKeyValue('IsDlg') === '1') {
        URL += "?IsDlg=1";
    }
    $("#aspnetForm").attr('action', location.pathname + "?Source=" + URL);
    return true;
}</script> 

Pass the custom URL instead of DispForm.aspx. It should work.

  • Thanks for replying, I am trying this way. And will I be able to get the ID of the added item? suppose, what if I want to pass the item id in the action attribute as query string parameter? – users1100 Oct 7 '14 at 9:33
  • you can refer the link : spjsblog.com/2011/04/23/… – Hardik Kothari Oct 7 '14 at 9:39
0

Try using _spPageContextInfo.webAbsoluteUrl

It gives you the absolute url of the web. So it will give http://<sitecollection/site/web/

  • it is taking _spPageContextInfo.webAbsoluteUrl as text, i.e. the __redirect includes _spPageContextInfo.webAbsoluteUrl as a part of url. – users1100 Oct 7 '14 at 8:27
  • You need to create a variable and then append it. Something like this: stackoverflow.com/questions/17814847/… – Garima Oct 7 '14 at 8:49
  • If I declare the variable in inline JavaScript, the thing is not getting updated. – users1100 Oct 7 '14 at 12:26

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.