apex:form Component
The apex:form
component is a Visualforce component in Salesforce that is used to create a form on a Visualforce page. It is the container for all form elements, and is required for any communication with the server using Apex.
Syntax
The syntax for the apex:form
component is as follows:
<apex:form [id="identifier string"] [style="CSS style"] [styleClass="CSS class"] [target="target window"]>
...form elements...
</apex:form>
Example
Consider the following example of a Visualforce page that uses the apex:form
component:
<apex:page controller="MyController">
<apex:form>
<apex:inputText label="Full Name" value="{!fullName}"/>
<apex:inputText label="Email" value="{!email}"/>
<apex:commandButton value="Submit" action="{!save}"/>
</apex:form>
</apex:page>
Explanation
In the above example, the apex:form
component is used as a container for three form elements - two input text fields for full name and email, and a command button to submit the form. The value
attributes of the input text fields are bound to instance variables in the controller, which can be accessed when the form is submitted.
Use
The apex:form
component is a crucial component in Visualforce for creating forms, accepting user input, and communicating with the server using Apex controllers. It is an essential part of any complex Visualforce page with forms.
Important Points
- The
apex:form
component should only be used as a container for form elements. It should not be used for styling or other purposes. - The
id
attribute can be used to uniquely identify the form for use in JavaScript functions. - The
style
andstyleClass
attributes can be used for styling the form using CSS. - The
target
attribute can be used to specify a target window for the form to submit to.
Summary
The apex:form
component is an essential Visualforce component used for creating forms on a Visualforce page. It allows for user input to be captured and processed in Apex controllers. The id
, style
, and styleClass
attributes can be used for identifying and styling the form, while the target
attribute can specify the target window for the form. The apex:form
component should only be used as a container for form elements.