apex:form

A section of a Visualforce page that allows users to enter input and then submit it with an <apex:commandButton> or <apex:commandLink>. The body of the form determines the data that is displayed and the way it’s processed. It’s a best practice to use only one <apex:form> tag in a page or custom component.

Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only <apex:inputField> and <apex:outputField> can be used with sObject fields.

As of API version 18.0, this tag can’t be a child component of <apex:repeat>.

This component supports HTML pass-through attributes using the “html-” prefix. Pass-through attributes are attached to the generated <form> tag.

Example 

1<!-- For this example to render properly, you must associate the Visualforce page 
2with a valid case record in the URL. 
3For example, if 001D000000IRt53 is the case ID, the resulting URL should be: 
4https://MyDomain_login_URL/apex/myPage?id=001D000000IRt53
5See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
6         
7
8<apex:page standardController="Case" recordSetVar="cases" tabstyle="case">
9    <apex:form id="changeStatusForm">
10        <apex:pageBlock >
11        <apex:pageMessages />
12        <apex:pageBlockButtons>
13            <apex:commandButton value="Save" action="{!save}"/>
14        </apex:pageBlockButtons>
15        <apex:pageBlockTable value="{!cases}" var="c">
16            <apex:column value="{!c.casenumber}"/>
17            <apex:column value="{!c.account.name}"/>
18            <apex:column value="{!c.contact.name}"/>
19            <apex:column value="{!c.subject}"/>
20            <apex:column headerValue="Status">
21                <apex:inputField value="{!c.Status}"/>
22            </apex:column>
23        </apex:pageBlockTable>
24        </apex:pageBlock>
25    </apex:form>
26</apex:page>

The example above renders the following HTML:

1<!-- allows you to change the status of your cases -->
2<form id="j_id0:changeStatusForm" name="j_id0:changeStatusForm" method="post"
3    action="/apex/sandbox" enctype="application/x-www-form-urlencoded">
4    <!-- opening div tags -->
5    <table border="0" cellpadding="0" cellspacing="0">
6        <tr>
7			<td class="pbTitle"> </td>
8            <td id="j_id0:changeStatusForm:j_id1:j_id29" class="pbButton">
9                <input type="submit"
10                    name="j_id0:changeStatusForm:j_id1:j_id29:j_id30"
11                    value="Save" class="btn"/>
12            </td>
13        </tr>
14    </table>
15    
16    <div class="pbBody">
17        <table class="list" border="0" cellpadding="0" cellspacing="0">
18            <colgroup span="5"/>
19            <thead>
20                <tr class="headerRow ">
21                    <th class="headerRow  " scope="col">Case Number</th>
22                    <th class="headerRow " scope="col">Account Name</th>
23                    <th class="headerRow  " scope="col">Name</th>
24                    <th class="headerRow  " scope="col">Subject</th>
25                    <th class="headerRow  " scope="col">Status</th>
26                </tr>
27            </thead>
28            
29            <tbody>
30                <tr class="dataRow even  first ">
31                    <td class="dataCell"><span>00001000</span></td>
32                    <td class="dataCell"><span>Edge Communications</span></td>
33                    <td class="dataCell"><span>Rose Gonzalez</span></td>
34                    <td class="dataCell"><span>Starting generator after electrical failure</span></td>
35                    <td class="dataCell">
36                        <select>
37                            <option value="">--None--</option>
38                            <option value="New">New</option>
39                            <option value="Working" selected="selected">Working</option>
40                            <option value="Escalated">Escalated</option>
41                            <option value="Closed">Closed</option>
42                        </select>
43                    </td>
44                </tr>
45                
46                <tr class="dataRow odd last ">
47                    <td class="dataCell"><span>00001027</span></td>
48                    <td class="dataCell"><span>Joyce Bookings</span></td>
49                    <td class="dataCell"><span>Andy Young</span></td>
50                    <td class="dataCell"><span>Checking paper jam</span></td>
51                    <td class="dataCell">
52                        <select>
53                            <option value="">--None--</option>
54                            <option value="New">New</option>
55                            <option value="Working" selected="selected">Working</option>
56                            <option value="Escalated">Escalated</option>
57                            <option value="Closed">Closed</option>
58                        </select>
59                    </td>
60                </tr>
61            </tbody>
62        </table>
63    </div>
64    <!-- closing div tags -->
65</form>

Attributes 

Attribute NameAttribute TypeDescriptionRequired?API VersionAccess
acceptStringA comma-separated list of content types that a server processing this form can handle. Possible values for this attribute include “text/html”, “image/png”, “image/gif”, “video/mpeg”, “text/css”, and “audio/basic”. For more information, including a complete list of possible values, see the W3C specifications. 10.0global
acceptcharsetStringA comma-separated list of character encodings that a server processing this form can handle. If not specified, this value defaults to “UNKNOWN”. 10.0global
dirStringThe direction in which the generated HTML component should be read. Possible values include “RTL” (right to left) or “LTR” (left to right). 10.0global
enctypeStringThe content type used to submit the form to the server. If not specified, this value defaults to “application/x-www-form-urlencoded”. 10.0global
forceSSLBooleanThe form will be submitted using SSL, regardless of whether the page itself was served with SSL. The default is false. If the value is false, the form will be submitted using the same protocol as the page. If forceSSL is set to true, when the form is submitted, the page returned will use SSL. 14.0
idStringAn identifier that allows the form component to be referenced by other components in the page. 10.0global
langStringThe base language for the generated HTML output, for example, “en” or “en-US”. For more information on this attribute, see the W3C specifications. 10.0global
onclickStringThe JavaScript invoked if the onclick event occurs–that is, if the user clicks the form. 10.0global
ondblclickStringThe JavaScript invoked if the ondblclick event occurs–that is, if the user clicks the form twice. 10.0global
onkeydownStringThe JavaScript invoked if the onkeydown event occurs–that is, if the user presses a keyboard key. 10.0global
onkeypressStringThe JavaScript invoked if the onkeypress event occurs–that is, if the user presses or holds down a keyboard key. 10.0global
onkeyupStringThe JavaScript invoked if the onkeyup event occurs–that is, if the user releases a keyboard key. 10.0global
onmousedownStringThe JavaScript invoked if the onmousedown event occurs–that is, if the user clicks a mouse button. 10.0global
onmousemoveStringThe JavaScript invoked if the onmousemove event occurs–that is, if the user moves the mouse pointer. 10.0global
onmouseoutStringThe JavaScript invoked if the onmouseout event occurs–that is, if the user moves the mouse pointer away from the form. 10.0global
onmouseoverStringThe JavaScript invoked if the onmouseover event occurs–that is, if the user moves the mouse pointer over the form. 10.0global
onmouseupStringThe JavaScript invoked if the onmouseup event occurs–that is, if the user releases the mouse button. 10.0global
onresetStringThe JavaScript invoked if the onreset event occurs–that is, if the user clicks the reset button on the form. 10.0global
onsubmitStringThe JavaScript invoked if the onsubmit event occurs–that is, if the user clicks the submit button on the form. 10.0global
prependIdBooleanA Boolean value that specifies whether or not this form should prepend its ID to the IDs of its child components during the clientid generation process. If not specified, the value defaults to true. 10.0global
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. 10.0global
styleStringThe style used to display the form component, used primarily for adding inline CSS styles. 10.0global
styleClassStringThe style class used to display the form component, used primarily to designate which CSS styles are applied when using an external CSS stylesheet. 10.0global
targetStringThe name of the frame that displays the response after the form is submitted. Possible values for this attribute include “_blank”, “_parent”, “_self”, and “_top”. You can also specify your own target names by assigning a value to the name attribute of a desired destination. 10.0global
titleStringThe text to display as a tooltip when the user’s mouse pointer hovers over this component. 10.0global

See Also