Form Submit from a WebPart SharePoint

Unfortunately a form element can’t exist within a web part. The form element already exists in the master page of the web part.

To resolve the issue the the jquery file jquery.SharePointFormSubmit.js file can be downloaded from to facilitate form submit from within the web part.  Instead of the real HTML, use a div and a button with the submit event attached.

However the script had to be modified slightly to work according to blog post

The code has been modified further to remove added ids to the input fields by SharePoint when the fields are rendered on the UI.

(function ($) {
$.fn.SharePointFormSubmit = function (element, method, action) {
var e; // new input element
var f = document.createElement("form"); // form
f.method = method;
f.action = action;
f.setAttribute("style", "display:none");
$(element).find("input, select, textarea").each(function () {
e = document.createElement("input")
e.setAttribute("type", $(this).attr("type"));
//id and name are modified when rendered on UI, use the delimitor txt_ to retrieve correct id and name
var inputId = $(this).attr("id").split("txt_");
if (inputId.length > 1) {
e.setAttribute("id", inputId[1]);
var inputName = $(this).attr("name").split("txt_");
if (inputName.length > 1) {
e.setAttribute("name", inputName[1]);
//e.setAttribute("name", $(this).attr("name"));
e.setAttribute("value", $(this).val());
var s = document.body.appendChild(f);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s