Popup warning message windowIn some occasions, like user agreement, you do need to be sure, that user has agreed with the form contents. Usually in such occasions is used standard check box element. Meanwhile check box cannot be a required element, because all its possible value is valid – checked or unchecked. Here we will show how to make check box a required element with only one allowed value – checked.

All we need is to add a small piece of JavaScript code, which will check current element value. In case check box is not checked, script will show popup warning message.

if (this.getField("Agree").value == "Yes") {
// if check box state is “checked”, 
// form data will be submitted to the SharePoint library 
   var extURL = PDFF.SystemData["DefaultAnonymousSubmitURL"];
    if (this.external) {
        eval("var sysData ="+this.getField("PDFSPSystemData").value);
        this.submitForm({cURL: (sysData.WebURL || "")+
            "/_layouts/PDFForms/PDF.aspx", cSubmitAs: "FDF" });
    } else {
        if (extURL) {
            extURL = PDFF.prepareURLWithPlatform(extURL, app.platform);
            this.submitForm({cURL: extURL, cSubmitAs: "FDF"});
        } else {
            app.alert("Anonymous Form submission is not supported");
        }
    }
}
else {
// otherwise warning message will be displayed
    app.alert({ cMsg: "You must accept terms and conditions first", 
        cTitle: "Warning" });
}

Since this code contains PDF Share Forms form submission code, it should replace standard code associated with “Save” button. To replace code, select “Save” button and click Actions button on the ribbon. Here we need to remove standard JavaScript code (click on the close button) and add custom (click on Javascript action in the menu on the left and drag-n-drop it in the main window). Click on the green field “enter script” and paste your code here. Press ok and deploy the form.

Save_Button_action_code Drag JavaScript code action JavaScript code

Popup warning message

Now, when new form is going to be submitted, user must accept terms and conditions in the form – the only correct state for the check box element is “checked”.

WATCH VIDEO

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.