You need to sign in to do that
Don't have an account?
Jasmine Jalaludheen
I created a Registration page which have some required fields and standard controller is User object .When I am not giving the values and click on the submit button it's not showing me the error msg.Any help will be appreciated
<apex:page standardController="User" extensions="RegistrationExt">
<apex:form >
<div id="logo" >
<img src="{!$Resource.logo}" width="20%"/>
<hr style="height:5px;background-color:orange"> </hr>
</div>
<div style="text-align: center;margin-top: 40px;" >
<span style="margin-right: 10px;">First Name</span><apex:inputText value="{!user.Name}" />
</div><br></br>
<div style="text-align: center;">
<span style="margin-right: 10px;">Last Name</span><apex:inputText value="{!User.Last_Name__c}" required="true" />
</div><br></br>
<div style="text-align: center;">
<span style="margin-right:38px;">Email</span><apex:inputText value="{!User.Email__c}" required="true" />
</div><br></br>
<div style="text-align: center;">
<span style="margin-right: 35px;">Phone</span><apex:inputText value="{!User.Phone}" required="true" />
</div><br></br>
<html>
<body>
<center>
<form >
<input type="checkbox" id="doc" value="{!USer.Profile}" />
<label for="doc"> Doctor</label>
<input type="checkbox" id="Nur" value="{!USer.Profile}" />
<label for="Nur"> Nurse</label>
<input type="checkbox" id="IntDoc" value="{!USer.Profile}"/>
<label for="IntDoc">Intern Doctor </label>
</form>
</center>
</body>
</html>
<!--Controller class-->
public with sharing class RegistrationExt {
User us;
public String confirmPwd {get;set;}
public RegistrationExt(ApexPages.StandardController con){
us = new User();
us = (User)con.getRecord();
}
public PageReference save() {
PageReference pr; //default value is null
if(String.isBlank(us.Password__c) || String.isBlank(confirmPwd)) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.Error,'Please enter both Password and Confirm Password.');
ApexPages.addMessage(msg);
}
else if(us.Password__c != confirmPwd) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.Error,'Password and Confirm Password mismatch.');
ApexPages.addMessage(msg);
}
else {
try {
insert us;
pr = Page.EMRPediatricsHome;
}
catch(Exception e) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.Error,e.getMessage());
ApexPages.addMessage(msg);
}
}
return pr;
}
}
<apex:form >
<div id="logo" >
<img src="{!$Resource.logo}" width="20%"/>
<hr style="height:5px;background-color:orange"> </hr>
</div>
<div style="text-align: center;margin-top: 40px;" >
<span style="margin-right: 10px;">First Name</span><apex:inputText value="{!user.Name}" />
</div><br></br>
<div style="text-align: center;">
<span style="margin-right: 10px;">Last Name</span><apex:inputText value="{!User.Last_Name__c}" required="true" />
</div><br></br>
<div style="text-align: center;">
<span style="margin-right:38px;">Email</span><apex:inputText value="{!User.Email__c}" required="true" />
</div><br></br>
<div style="text-align: center;">
<span style="margin-right: 35px;">Phone</span><apex:inputText value="{!User.Phone}" required="true" />
</div><br></br>
<html>
<body>
<center>
<form >
<input type="checkbox" id="doc" value="{!USer.Profile}" />
<label for="doc"> Doctor</label>
<input type="checkbox" id="Nur" value="{!USer.Profile}" />
<label for="Nur"> Nurse</label>
<input type="checkbox" id="IntDoc" value="{!USer.Profile}"/>
<label for="IntDoc">Intern Doctor </label>
</form>
</center>
</body>
</html>
<!--Controller class-->
public with sharing class RegistrationExt {
User us;
public String confirmPwd {get;set;}
public RegistrationExt(ApexPages.StandardController con){
us = new User();
us = (User)con.getRecord();
}
public PageReference save() {
PageReference pr; //default value is null
if(String.isBlank(us.Password__c) || String.isBlank(confirmPwd)) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.Error,'Please enter both Password and Confirm Password.');
ApexPages.addMessage(msg);
}
else if(us.Password__c != confirmPwd) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.Error,'Password and Confirm Password mismatch.');
ApexPages.addMessage(msg);
}
else {
try {
insert us;
pr = Page.EMRPediatricsHome;
}
catch(Exception e) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.Error,e.getMessage());
ApexPages.addMessage(msg);
}
}
return pr;
}
}
I found a documentation link that has below implementation of validation of visualforce page and as mentioned can you try checking if possible using all the supported tags link the ones present in the below implementation:
Link: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_validation.htm#:~:text=If%20a%20user%20enters%20data,displayed%20on%20the%20Visualforce%20page.
Let me know in case if there are any questions.
Regards,
Anutej
You have added the page message from controller class but there is no page message tag used in your VF page. Please add the below tag in your VF page under the apex form:
<apex:pageMessages />
Make sure to reRender the form after the submit button is clicked. Let me know if you need more information on this.
Thanks,
Abhishek Bansal.
@SFDC_Saurabh , Thank you for your response.I tried using <apex:inputField> instead of <input> tag ,not working
@ANUTEJ ,Thank you for your response.As I am a beginer I didn't understand your suggestion,but i will try and let you know
Please replace the below code:
If this doesn't work then we need to have a look into your org and figure out some solution. You can directly reach out to me.
Thanks,
Abhishek Bansal.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790