function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cjcindccjcindc 

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>
cjcindccjcindc
repaste of incomplete code:

<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>
Virginia Y FerrerVirginia Y Ferrer
Hi, have you been able to solve it? I have the same problem ... I am not finding a solution.
Giritharakannan DevarajGiritharakannan Devaraj

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..