New to Infopath: How do I create a button that sends a form post to another website? - InfoPath Dev
in

InfoPath Dev

New to Infopath: How do I create a button that sends a form post to another website?

Last post 10-22-2010 06:15 PM by Ted Fitch. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 10-20-2010 09:01 PM

    New to Infopath: How do I create a button that sends a form post to another website?

     Hi;

     I am totally new to InfoPath.

     I need to accomplish the following:

     To create a button or link on an InfoPath template, so when the user clicks on that button it takes the username & password from the page and launches a website and logs in the user.

     The website accepts a POST.

     I can do it on a regular HTML page with some script that creates a form on the fly and does a submit.

     I am trying to use the same script on an InfoPath button but it doesnt work.

     What am I doing wrong? is there any other way that I can accomplish what i need?

     Pleas help me!

     

    Thank you

     

    Below is my HTML code:

    <HTML>
    <Head>
    
    		<script language="JavaScript">
    		<!--
    
    		function getNewSubmitForm()
    		{
    			var submitForm = document.createElement("FORM");
    			 document.body.appendChild(submitForm);
    			submitForm.method = "POST";
    			return submitForm;
    		}
    
    		//helper function to add elements to the form
    		function createNewFormElement(inputForm, elementName, elementValue){
    			var newElement = document.createElement("input");
    			inputForm.appendChild(newElement);
    			newElement.name = elementName;
    			newElement.type = 'hidden';
    			newElement.value = elementValue;
    			return newElement;
    		} 
    
    		//function that creates the form, adds some elements
    		//and then submits it
    		function sprintLogin()
    		{
    			var strUser = document.getElementById('username').value;
    			var strPassword = document.getElementById('pass').value;
    			var strLoginMode = 'deepLinkURL';
    			var strTraget = '/mysprint/pages/secure/SigninServlet?targetPage=/mysprint/pages/sl/global/index.jsp';
    			var strAction = "https://mysprint.sprint.com/entrycheck/login.fcc";
    			
    // alert(strUser);
    // alert(strPassword);
    			var submitForm = getNewSubmitForm();
    			createNewFormElement(submitForm, "USER", strUser );
    			createNewFormElement(submitForm, "PASSWORD", strPassword );
    			createNewFormElement(submitForm, "LOGINMODE", strLoginMode );
    			createNewFormElement(submitForm, "target", strTraget );
    			submitForm.action = strAction;
    			submitForm.submit();
    		}
    		-->
    		</script>
    </Head>
    
    	<BODY>
    
    		User name : <input type="text" name="username" id="username" /><br><br>
    		Password : <input type="password" name="pass" id="pass" /><br><br><br>
    
    		<button type="button" onClick="sprintLogin()">Sprint Login...</button>
    </BODY>
    </HTML>  
     

     The following is the code I am trying to use in InfoPath:

     function getNewSubmitForm()
            {
                var submitForm = XDocument.DOM.createElement("FORM");
                 XDocument.DOM.appendChild(submitForm);
                submitForm.method = "POST";
                return submitForm;
            }

            //helper function to add elements to the form
            function createNewFormElement(inputForm, elementName, elementValue){
                var newElement =XDocument.DOM.createElement("input");
                inputForm.appendChild(newElement);
                newElement.name = elementName;
                newElement.type = 'hidden';
                newElement.value = elementValue;
                return newElement;
            }

            //function that creates the form, adds some elements
            //and then submits it
            function sprintLogin()
            {
                //</my:field51>
                var strUser = XDocument.DOM.selectSingleNode("//my:field51").text
                var strPassword = XDocument.DOM.selectSingleNode("//my:field52").text

                var strLoginMode = 'deepLinkURL';
                var strTraget = '/mysprint/pages/secure/SigninServlet?targetPage=/mysprint/pages/sl/global/index.jsp';
                var strAction = "https://mysprint.sprint.com/entrycheck/login.fcc";
                
                var submitForm = getNewSubmitForm();
                createNewFormElement(submitForm, "USER", strUser );
                createNewFormElement(submitForm, "PASSWORD", strPassword );
                createNewFormElement(submitForm, "LOGINMODE", strLoginMode );
                createNewFormElement(submitForm, "target", strTraget );
                submitForm.action = strAction;
                submitForm.submit();
            }

     

    I add code to the OnClick event on the Button to call the SprintLogin() procedure.

     

     

  • 10-22-2010 06:15 PM In reply to

    Re: New to Infopath: How do I create a button that sends a form post to another website?

    Hi ShayBod,

    Did you already try creating a hyperlink by concacetnating values in InfoPath?

    Using concat you should be able to do this (see this blog that talks about concat in general: http://blogs.msdn.com/b/infopath/archive/2006/04/05/569338.aspx)

    However you should know that storing the users name and password in the form that way would not be very secure.

    Also, how are you going to get the users password?

    Ted

     

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.