2013-07-27 42 views
1

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

我在网上搜索,但我没有找到任何解决方案。也是新的分享点。如果任何人可以提供一些链接,这将是有帮助的。

谢谢

回答

4

是的,这是非常有可能使用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工作站工作,所以如果你仍然有这个问题,让我知道。

0

您可以使用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> 
相关问题