【问题标题】:webpart form submit to custom list in sharepointwebpart 表单提交到 sharepoint 中的自定义列表
【发布时间】:2013-07-27 17:01:18
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: sharepoint web-parts custom-lists


    【解决方案1】:

    是的,这很可能使用 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 站所在的工作地点,所以如果您对此仍有疑问,请告诉我。

    【讨论】:

      【解决方案2】:

      您也可以使用 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' />
      

      SP 服务

      <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>
      

      【讨论】:

        猜你喜欢
        • 2021-01-16
        • 2011-07-10
        • 2018-08-20
        • 2018-10-24
        • 2011-08-23
        • 2013-12-21
        • 2011-08-24
        • 2013-12-01
        • 1970-01-01
        相关资源
        最近更新 更多