none
Validation and redirect button at sharepoint list form RRS feed

Answers

  • Hi Ameenah,

    According to your post, my understanding is that you want to intercept the submit action in order to do some validations. Then redirect the page to another page after submitting.

    You can use JQuery to achieve that. The following script for your reference:

    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    
    $(document).ready(function () {
    
    var button = $('input[name$="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, "http://sp/SitePages/soap1.aspx");
    
                if (!validate()) return false;//validation
    
                if (!PreSaveItem()) return false;  
    
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
    
    });
    
    });
    
    //validation
    
        function validate() {
    
            var flag = true;
    
            //add your logic here 
    
            if (condition) {
    
                //some logic
    
                flag = false;
    
            }
    
            return flag;
    
        }
    
    </script>
    

    Best regards,

    Linda Zhang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Wednesday, March 23, 2016 11:32 AM
    Moderator

All replies

  • For better understanding please provide details information.

    We aren't getting what issue you are facing.

    Thanks/ Siddheshwar kohale

    Tuesday, March 22, 2016 9:22 AM
  • Hello,

    I used RedirectUrl as below :

    <td class="ms-toolbar" nowrap="nowrap">
    <SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton2" RedirectUrl="http://portal.com/hj/fwdbck/Pages/Admin.aspx"/>
    </td>
    

    but the validation for column list is not working.

    When user click on Save button without insert any data in column list, the .aspx form will be directly to http://portal.com/hj/fwdbck/Pages/Admin.aspx, by right should have validation.

    Thanks

    • Marked as answer by Ameenah Thursday, February 1, 2018 2:53 AM
    • Unmarked as answer by Ameenah Thursday, February 1, 2018 2:53 AM
    Wednesday, March 23, 2016 5:04 AM
  • Hi Ameenah,

    According to your post, my understanding is that you want to intercept the submit action in order to do some validations. Then redirect the page to another page after submitting.

    You can use JQuery to achieve that. The following script for your reference:

    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    
    $(document).ready(function () {
    
    var button = $('input[name$="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, "http://sp/SitePages/soap1.aspx");
    
                if (!validate()) return false;//validation
    
                if (!PreSaveItem()) return false;  
    
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
    
    });
    
    });
    
    //validation
    
        function validate() {
    
            var flag = true;
    
            //add your logic here 
    
            if (condition) {
    
                //some logic
    
                flag = false;
    
            }
    
            return flag;
    
        }
    
    </script>
    

    Best regards,

    Linda Zhang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Wednesday, March 23, 2016 11:32 AM
    Moderator
  • On My case it was not working because the method SPClientForms.ClientFormManager.SubmitClientForm was missing and this method is requred.

    So I followed the direction in the following site:

    http://spoodoo.com/change-default-form-button-redirect-simple-way/

    This is the method I used:

    function changeRedirect(options) {
        for(var i = 0, buttons = document.querySelectorAll(options.selector); i < buttons.length; i++){
            buttons[i].setAttribute(
                "onclick", 
                "Nav.navigate = STSNavigate = function(){"+
                "   window.location = '" + options.redirectTo + "'"+
                "};"+
                buttons[i].getAttribute("onclick")
            )
        }
    }
     
    document.addEventListener("DOMContentLoaded", function(event) {
        changeRedirect({
            selector:   "input[value=Save]",
            redirectTo: "https://google.com"
        })
        changeRedirect({
            selector:   "input[value=Cancel]",
            redirectTo: "https://bing.com"
        })
    })




    • Edited by Neo ArcMon Wednesday, January 31, 2018 8:08 PM
    Wednesday, January 31, 2018 8:07 PM