How to get the apex:inputText fields values into the apex controller class from visualforce page?
VF page having some apex:inputText fields and one custom button and on clicking of the button, the values in the apex:inputText field should be passed to the apex controller class to save it in the database.
Its possible to achieve using the below way.
Apex Class:
public with sharing class textInputsCont { public String inputText1{get;set;} // input text1 value from visualforce page public String inputText2{get;set;} // input text2 value from visualforce page public void saveTextValue(){ Account a = new Account(); a.TextField1__c = inputText1; // Field Assignment1 a.TextField2__c = inputText2; // Field Assignment2 insert a; // DML Operations } }
Visualforce Page:
<apex:page showHeader="false" sidebar="False" controller="textInputsCont"> <apex:form > Input Text1 <apex:inputText value="{!inputText1}"/> Input Text2 <apex:inputText value="{!inputText2}"/> <apex:commandButton value="save" action="{!saveTextValue}"/> </apex:form> </apex:page>
Here:
Account is a Standard Object – same way we can use with either standard object or custom object
TextField1__c and TextField2__c is a custom field from Account object.