1

i am working on submitting a form and passing lastname and firstname and redirect search to http://data. but when i click enter or click submit button it does not redirect to http://data and it just reload the correct page

The current code is place under script editor webpart

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
 <script type="text/javascript" src="http://jquerysharepointform.googlecode.com/files/jquery.SharePointFormSubmit.js">


<script>
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"));
                    e.setAttribute("id", $(this).attr("id"));
                   e.setAttribute("name", $(this).attr("name"));
                    e.setAttribute("value", $(this).val());
                  e.setAttribute("checked", $(this).attr("checked"));
                  e.setAttribute("multiple", $(this).attr("multiple"));
                    f.appendChild(e);
                });

                var s = document.body.appendChild(f);
                s.submit();
        };
    })(jQuery);
</script>

<div id="divIdForm">
  <h2>People &amp; Places Search</h2>

  <input type="text" name="firstName id="firstName" value="" size="21" maxlength="50" />
  <input type="text" name="lastName" id="lastName" value="" size="22" maxlength="50" />


    <input type="submit" value="" class="search" onclick="jQuery().SharePointFormSubmit('#divIdForm', 'post','http://data/default.aspx')">


</div>
1

Each Sharepoint page is embedded into a <form> already, so I see two options here:

  1. You could try to change the action of the form #aspnetForm: $('#aspnetForm').attr("action","http://data/default.aspx") — and adapt your code to not create your own <form> but just add the fields you want into the page... I think it's the cleanest way to do it
  2. Or you can define WebForm_OnSubmit=function() { return false } to block the original <form> and then just use your code as it is
0

Solution:

1. Create a HTML file which contain the following file

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
 <script type="text/javascript" src="http://jquerysharepointform.googlecode.com/files/jquery.SharePointFormSubmit.js">


<script>
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"));
                    e.setAttribute("id", $(this).attr("id"));
                   e.setAttribute("name", $(this).attr("name"));
                    e.setAttribute("value", $(this).val());
                  e.setAttribute("checked", $(this).attr("checked"));
                  e.setAttribute("multiple", $(this).attr("multiple"));
                    f.appendChild(e);
                });

                var s = document.body.appendChild(f);
                s.submit();
        };
    })(jQuery);
</script>

<div id="divIdForm">
  <h2>People &amp; Places Search</h2>

  <input type="text" name="firstName id="firstName" value="" size="21" maxlength="50" />
  <input type="text" name="lastName" id="lastName" value="" size="22" maxlength="50" />


    <input type="submit" value="" class="search" onclick="jQuery().SharePointFormSubmit('#divIdForm', 'post','http://data/default.aspx')">


</div>

2. Add PageViewer Webpart on the page and link to HTML file created above

3. In order to make HTML render content in SharePoint, i need to run the following script

function Add-SPAllowedInlineDownloadedMimeType{
    [CmdLetBinding()]
    param(
        [Parameter(Mandatory=$true, Position=0, ValueFromPipeLine=$true)]
        [Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]$WebApplication,
        [Parameter(Mandatory=$true, Position=1)]
        [string]$MimeType
    )
    process{
        $actualWebApp = $WebApplication.Read()
        if ($actualWebApp.AllowedInlineDownloadedMimeTypes -notcontains $mimetype)
        {
           Write-Host "Adding MIME Type..."
           $actualWebApp.AllowedInlineDownloadedMimeTypes.Add($mimetype)
           $actualWebApp.Update()
           Write-Host "Done."
        } Else {
           Write-Host -ForegroundColor Green "MIME type is already added."
        }
    }
}

$url = http://contoso.com
Add-SPAllowedInlineDownloadedMimeType -WebApplication $url -MimeType "text/html"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.