You need to sign in to do that
Don't have an account?

Show error message on apex:inputText field
I have a set of apex:inputText fields. I am trying to validate mandatory fields and display error messages next to fields. The code I have is:
Controller:
Currently I am trying this only for Applicatnt's EA ID field but when I click on Submit nothing happens. The debug statements in charge() are not called and nor is any error displayed. Am I missing anything here?
Thanks,
Vandana
<apex:page standardController="Case" extensions="MSAFTController" showHeader="false" standardStylesheets="true"> <apex:includeScript id="script2" value="{!URLFOR($Resource.ChargentCases__CreditCardJS, 'bililiteRange.js')}" loadOnReady="false"/> <meta http-equiv="X-Frame-Options" content="deny" /> <script> if( self == top ) { document.documentElement.style.display = 'block' ; } else { top.location = self.location ; } </script> <!--<apex:pageMessages id="msgs"/>--> <apex:outputPanel layout="block" styleClass="page"> <apex:stylesheet value="{!URLFOR($Resource.ChargentCases__CreditCardJS, 'style.css')}"/> <apex:stylesheet value="{!URLFOR($Resource.ChargentCases__CreditCardJS, 'sitepaymentStyle.css')}"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <style> @-moz-document url-prefix() { .ccjs-card .ccjs-expiration:after { top: 0em !important; } } </style> <apex:form id="frm"> <!--<apex:commandButton value="Submit Page" action="{!myMethod}"/> --> <apex:panelGrid columns="1" styleClass="info" width="100%"> <apex:pageBlock mode="edit" id="pblck"> <!--<apex:pageblockbuttons > <apex:commandbutton value="Submit" action="{!submit}" /> <apex:commandbutton value="Cancel" action="{!Cancel}"/> </apex:pageblockbuttons>--> <apex:pageblocksection id="FTDetails" title="MSA Fast Track"> <!--<div class="ccjs-card" id="innerForm">--> <apex:panelGrid columns="1" styleClass="info" > <apex:pageBlockSectionItem > <!--<apex:outputLabel for="MSA Application Number">MSA Application Number</apex:outputLabel>--> <apex:outputText value="MSA Application Number" /> <apex:inputText value="{!case.MSA_Application_Number__c}" styleClass="inputText" /> <!--<apex:inputField id="msaAppNo" value="{!case.MSA_Application_Number__c}" />--> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="Applicatnt's EA ID" /> <apex:outputPanel > <div class="requiredInput" id="divInp"> <div class="requiredBlock" id="divReq"></div> <!--apex:inputText value="{!case.Applicatnt_s_EA_ID__c}" id="appEAID" styleClass="inputText" required="true"/>--> <apex:inputText value="{!msaAppEAID}" id="appEAID" styleClass="inputText" rendered="{!LEN(errorMessage)==0}"/> <!--<apex:outputText id="errEAID" value="errorMessage" styleClass="classErrorClass" rendered="{!LEN(errorMessage)>0}"/>--> <apex:outputPanel rendered="{!LEN(errorMessage)!=0}"> <apex:inputText styleClass="error" value="{!msaAppEAID}"/> <div class="errorMsg"><strong>Error:</strong> {!msaAppEAID}</div> </apex:outputPanel> </div> </apex:outputPanel> <!--<apex:outputLabel for="Applicatnt's EA ID">Applicatnt's EA ID</apex:outputLabel> <apex:inputField required="true" id="msaAppEAID" value="{!case.Applicatnt_s_EA_ID__c}" />--> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="Applicant's Full Name" /> <apex:outputPanel > <div class="requiredInput"> <div class="requiredBlock"></div> <apex:inputText value="{!case.Applicants_Full_Name__c}" styleClass="inputText" required="true"/> <!--<apex:outputText id="errEAID" value="Error: You must enter a value" style="color:red;display:none"/>--> <!--<apex:outputText value="{!errorMessage}" style="color:red;display:none" rendered="{!LEN(errorMessage)>0}"/>--> </div> </apex:outputPanel> <!--<apex:outputLabel for="Applicant's Full Name">Applicant's Full Name</apex:outputLabel> <apex:inputField required="true" id="msaAppFullName" value="{!case.Applicants_Full_Name__c}" />--> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="Applicant's email address" /> <apex:inputText value="{!case.Applicant_s_email_address__c}" styleClass="inputText" required="true"/> <!--<apex:outputLabel for="Applicant's email address">Applicant's email address</apex:outputLabel> <apex:inputField id="msaAppEmail" value="{!case.Applicant_s_email_address__c}" />--> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="Payee's Full Name" /> <apex:outputPanel > <div class="requiredInput"> <div class="requiredBlock"></div> <apex:inputText value="{!case.Payees_Full_Name__c}" styleClass="inputText" required="true"/> </div> </apex:outputPanel> <!--<apex:outputLabel for="Payees Full Name">Payees Full Name</apex:outputLabel> <apex:inputField required="true" id="msaPayeeFN" value="{!case.Payees_Full_Name__c}" />--> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="Contact email address" /> <apex:outputPanel > <div class="requiredInput"> <div class="requiredBlock"></div> <apex:inputText value="{!case.Contact_email_address__c}" styleClass="inputText" required="true"/> </div> </apex:outputPanel> <!--<apex:outputLabel for="Contact email address">Contact email address</apex:outputLabel> <apex:inputField required="true" id="msaContactEmail" value="{!case.Contact_email_address__c}" />--> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText value="Additional Information" /> <apex:inputTextarea value="{!case.Additional_Information__c}" required="true" rows="10"/> <!--<apex:outputLabel for="Additional Information">Additional Information</apex:outputLabel> <apex:inputField id="msaAddnlInfo" value="{!case.Additional_Information__c}" />--> </apex:pageBlockSectionItem> <apex:outputPanel layout="block" styleClass="btns"> <!--<apex:commandButton value="Submit" action="{!charge}" rerender="msgs"/>--> <apex:commandButton value="Submit" action="{!charge}" /> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:outputPanel> </apex:panelGrid> <!-- onclick="if (!checkRequiredFields()) return false;" --> </apex:pageblocksection> <!--</div>--> </apex:pageBlock> </apex:panelGrid> </apex:form> </apex:outputPanel> <script type="text/javascript"> </apex:page>
Controller:
public class MSAFTController { public String msaAppEAID {get;set;} public String errorMessage {get;set;} //public String classErrorClass {get;set;} public ApexPages.StandardController standardContactController; private string req_param; private Case msaCase; public MSAFTController.MSAFTController(ApexPages.StandardController controller){ standardContactController = controller; msaCase =(Case) controller.getRecord(); errorMessage = ''; } public Id createCase(){ Id ftRecTypeId = [SELECT Id from recordType where name='MSA Fast Track' and sObjectType='Case' LIMIT 1].id; Id ctId = [Select Id from Contact where EA_Member_No__c=: msaCase.Applicatnt_s_EA_ID__c LIMIT 1].Id; Id gatewayId = [Select Id from ChargentBase__Gateway__c where Name='eWay Gateway' LIMIT 1].Id; Case insCase = new Case(); insCase.RecordTypeId = ftRecTypeId; insCase.Status = 'New'; insCase.Origin = 'Web'; insCase.ContactId = ctId; insCase.ChargentCases__Amount__c = 120.0; insCase.ChargentCases__Payment_Method__c = 'Credit Card'; insCase.MSA_Application_Number__c = msaCase.MSA_Application_Number__c; //insCase.MSA_Application_Number__c = msaAppEAID; insCase.Applicants_Full_Name__c = msaCase.Applicants_Full_Name__c; insCase.Applicatnt_s_EA_ID__c = msaCase.Applicatnt_s_EA_ID__c; insCase.Applicant_s_email_address__c = msaCase.Applicant_s_email_address__c; insCase.Payees_Full_Name__c = msaCase.Payees_Full_Name__c; insCase.Contact_email_address__c = msaCase.Contact_email_address__c; insCase.Additional_Information__c = msaCase.Additional_Information__c; insCase.ChargentCases__Gateway__c = gatewayId; insert insCase; System.debug('insCaseId>>>' + insCase.Id); return insCase.Id; } public pageReference charge(){ System.debug('Ind=side submit function*****************'); if(msaAppEAID == '' || msaAppEAID == null){ errorMessage = 'Required Field Empty'; } //boolean errorInSave = validate(); //System.debug('errorInSave >>>>>>>>>' + errorInSave); //if(errorInSave != true){ Id caseId = createCase(); /* Appfrontier Added */ ChargentCases__Payment_Request__c pReq = [Select ChargentCases__Pay_Link__c From ChargentCases__Payment_Request__c Where ChargentCases__Case__c = :caseID And ChargentCases__Status__c != 'Paid']; Pagereference pr = New PageReference(pReq.ChargentCases__Pay_Link__c); return pr; //} /* End Appfrontier Add */ /* req_param = apexPages.currentPage().getParameters().get('req'); System.debug('req_param>>>' + req_param); //Pagereference pr1 = new Pagereference('/apex/ChargentCases_SitePayment'); Pagereference pr = Page.MSA_CCDetailsPage; //Pagereference pr = Page.MSA_StartPage; pr.getParameters().put('req',caseId); //pr1.getParameters().put('req','%2FLVo2VwkvkZp3PG61h2oGDuYMIpLmDd%2BvBl93XXn%2FKiHqplGvB5gbrkp7YJ4xIif3W1wDKcFZlfGrHHJPPeGwIMzcEQxld1nkulatNzGZB4%3D'); //System.debug('pr1 in submit >>>' + pr1); System.debug('pr in submit >>>' + pr); //pr.setRedirect(true); //ChargentCases.TChargentOperations.TChargentResult rs= ChargentCases.TChargentOperations.ChargeCase_Click(caseId ); // System.debug('rs >>>>>' + rs); return pr; */ } /*public boolean validate() { boolean error = false; System.debug('In Validate>>>'); System.debug('msaAppEAID>>>' + msaAppEAID); if ((insCase.Applicatnt_s_EA_ID__c == '') || (insCase.Applicatnt_s_EA_ID__c == null)) { System.debug('msaCase.Applicatnt_s_EA_ID__c is blank'); classErrorClass = 'errorClass'; // put the errorclass, red borders<br> errorMessage = 'Postal code not found'; error = true; return error; } else { classErrorClass = ''; errorMessage = ''; error = false; return error; } return error; //return null; }*/ }
Currently I am trying this only for Applicatnt's EA ID field but when I click on Submit nothing happens. The debug statements in charge() are not called and nor is any error displayed. Am I missing anything here?
Thanks,
Vandana
Regards
All Answers
Either you can update your apex:inputText elements to utilize apex:inputField elements instead, or you could utilize the apex:message element inline with your inputText elements as pointed out in this post: https://developer.salesforce.com/forums/?id=906F000000096SiIAI
Regards