You need to sign in to do that
Don't have an account?
cjcindc
How to auto-submit form in visualforce page
I have a visualforce page with an html form. The form is a post method, has 2 hidden inputs and is targeted to an apex:iframe. I can't figure out how to get the form to auto-post to eliminate an extra click (submit button) for my users. The <body onload> does not appear to be working. I'm probably doing it all wrong. Thanks in advance for your thoughts/input.
<apex:page controller="myController" tabStyle="Contact" showHeader="true" sidebar="true" >
<html >
<body onload="document.myForm.submit()" >
<form action="{!sessionLink}" method="post" id="myForm" name="myForm" target="myFrame" >
<input type="hidden" name="X-BEARER-TOKEN" value="{!bearerToken}" />
<input type="hidden" name="X-REFRESH-TOKEN" value="{!refreshToken}" />
<center ><input type="submit" name="submit" value="initiate {!vendor} session" /></center>
</form>
</body>
</html>
<apex:page controller="myController" tabStyle="Contact" showHeader="true" sidebar="true" >
<html >
<body onload="document.myForm.submit()" >
<form action="{!sessionLink}" method="post" id="myForm" name="myForm" target="myFrame" >
<input type="hidden" name="X-BEARER-TOKEN" value="{!bearerToken}" />
<input type="hidden" name="X-REFRESH-TOKEN" value="{!refreshToken}" />
<center ><input type="submit" name="submit" value="initiate {!vendor} session" /></center>
</form>
</body>
</html>
<apex:page controller="myController" tabStyle="Contact" showHeader="true" sidebar="true" >
<html >
<body onload="document.myForm.submit()" >
<form action="{!sessionLink}" method="post" id="myForm" name="myForm" target="myFrame" >
<input type="hidden" name="X-BEARER-TOKEN" value="{!bearerToken}" />
<input type="hidden" name="X-REFRESH-TOKEN" value="{!refreshToken}" />
<center ><input type="submit" name="submit" value="initiate {!vendor} session" /></center>
</form>
</body>
</html>
<br/>
<apex:iframe scrolling="true" id="myFrame" frameBorder="true" width="100%" />
</apex:page>
Hi cjcndic & Ferrer,
Please use this format for auto submit the form in visualforce page...
<apex:page id="pg" standardController="Account" extensions="SampleController" showHeader="false" >
<base target="_parent" />
<form id="frm" action="{!sessionLink}" method="post">
<input type="hidden" name="Name1" value="{!Value1}"/>
<input type="hidden" name="Name2" value="{!Value2}"/>
</form>
<script>
window.onload = ()=>{document.getElementById('frm').submit();}
</script>
</apex:page>
It may resolve your issue. If it really useful please select this solution as best answer...Thanks in advance..