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
RICITRICIT 

Submit HTML Form

Hello. I need to replicatethe functionality of:

 

<body onload="document.getElementById('form').submit()>

<form id="form" method="post" action="http://localhost/Salesforce/testphp.php">

...(inputs with field data from salesforce)...

</form>

</body>

 

in a Visualforce Page.

 

Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
bmabma

If you page uses the standard SF header, the body tag is ignored.

 

There are 2 ways to accomplish this.

1.  set showHeader to false

 

<apex:page showHeader="false"> <body onload="alert('hi');"> 1234 </body> </apex:page>

 

 2. move the javascript call from onload to the end of the page

<apex:page> <script> <!-- put this at the end of the page --> alert('hi'); </script> </apex:page>

 

 

 

All Answers

bob_buzzardbob_buzzard

There is no reason why you can't have that.

 

The onload handler might give you some problems - I have read on the boards that it is not always reliable, though where I've used it to date it has been.

 

You can populate the value of the inputs with values from SalesForce using property values from your controller or field values from sObjects.

 

You can mix and match HTML with VisualForce components, so there will be no problem embedding that form. 

RICITRICIT

Thank you for your quick response.

I am indeed getting issues with the onload handler; it is not functioning. The page loads and just sits there, instead of submitting the form. Ideas?

Thanks again.

bmabma

If you page uses the standard SF header, the body tag is ignored.

 

There are 2 ways to accomplish this.

1.  set showHeader to false

 

<apex:page showHeader="false"> <body onload="alert('hi');"> 1234 </body> </apex:page>

 

 2. move the javascript call from onload to the end of the page

<apex:page> <script> <!-- put this at the end of the page --> alert('hi'); </script> </apex:page>

 

 

 

This was selected as the best answer
bob_buzzardbob_buzzard
Ah, so that's why I've not had problems with onload handlers - all of my pages are completely custom and don't use SaleForce headers.  Good to know.
RICITRICIT

Great! First one worked like a charm!

 Thank you.