How to get the text fields values in the controller class without using any scripts

  • Im having a VF page it has some text fields and one button . On clicking the button , the values in the text field should be passed to the controller class to save in the database . Can this be achieved . If yes , direct me .

  • Venkatesh

    Venkatesh Correct answer

    8 years ago

    i think this is one way

    <apex:page showHeader="false" sidebar="False" controller="textInputsCon">
    
    <apex:form >
    
       Input Text1 <apex:inputText value="{!inputText1}"/>
       Input Text2 <apex:inputText value="{!inputText2}"/>
    
        <apex:commandButton value="save" action="{!saveList}"/>
    </apex:form>
    

    controller

        public with sharing class textInputsCon {
    
         public String inputText1{get;set;} // input text1 value  from vf
         public String inputText2{get;set;} // input text2 value  from vf
    
          public void saveList(){
    
            salesObj  salesObjInst = new salesObj(); //  Either salesObj is standard or custom object
    
            salesObj.field1 =  inputText1;  // Field Assignment
            salesObj.field2 =  inputText2;  // Field Assignment
    
            insert  salesObj; // DML Operations
    
          }  
    
    }
    

    Another way , if you want call save action from the command button with out navigating to controller , you can use java script remoting.

    Define one java script function same as a object, and call this function from the onclick event of button, check the below link

    http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting_example.htm

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM