首页 文章

webpart表单提交到sharepoint中的自定义列表

提问于
浏览
1

是否可以使用名称,电子邮件,地址和提交按钮等字段创建表单可视webpart . 用户提交数据后应提交到sharepoint自定义列表,此处自定义列表将具有相同的字段,如姓名,电子邮件,地址 . 我创建了一个自定义列表 .

我在互联网上搜索,但我没有找到任何解决方案 . 也是sharepoint的新手 . 如果任何人可以提供一些链接,它将是有帮助的 .

谢谢

2 回答

  • 0

    是的,这很可能使用jQuery和AJAX .

    所以,让我们说,简单来说,这是你的输入:

    <input type='text' id='name' />
    <input type='submit' id='submitdata' value='submit />
    

    使用jquery,你会这样做:

    $(function(){
    
        $('#submitdata').click(function(){
            //this gets the value from your name input
            var name = $('#name').val();
            var list = "PutYourListNameHere";
    
            addListItem(name, list);
        });
    
    });
    
    function addListItem(name, listname) {
    
    var listType = "PutTheTypeOfListHere";
    
    // Prepping our update & building the data object.
    // Template: "nameOfField" : "dataToPutInField"
    var item = {
        "__metadata": { "type": listType},
        "name": name
    }
    
    // Executing our add
    $.ajax({
        url: url + "/_api/web/lists/getbytitle('" + listname + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            console.log("Success!");
            console.log(data); // Returns the newly created list item information
        },
        error: function (data) {
            console.log("Error!");
            console.log(data);
        }
    });
    
    }
    

    这应该工作 . 我不在我的SharePoint工作站工作,所以如果你仍然遇到问题,请告诉我 .

  • 4

    您也可以使用SPServices,它会工作

    <script type="text/javascript" src="~/jquery-1.5.2.min.js"></script>
    <script type="text/javascript" src="~/jquery.SPServices-0.7.2.min.js"></script>
    

    HTML

    <input type='text' id='name' />
    <input type='text' id='email' />
    <input type='text' id='mobile' />
    <input type='submit' id='submit' value='Submit' />
    

    SPServices

    <script type="text/javascript">
    $("#submit").click(function(){
    
        var Fname=$("#name").val();
        var Email =$("#email").val();
        var Mobile =$("#mobile").val();
    
        $().SPServices({ 
            operation: "UpdateListItems", 
            async: false, 
            batchCmd: "New", 
            listName: "YourCustomListName", 
            valuepairs: [["Fname", Fname], ["Email", Email], ["Mobile", Mobile]], //"Fname","EMail" and "Mobile" are Fields Name of your custom list
            completefunc: function(xData, status) { 
    
                if (status == "success") {
                    alert ("Thank you for your inquiry!" );
                }
                else {
                    alert ("Unable to submit your request at this time.");
                }
    
            }
        });
    });
    </script>
    

相关问题