+ Start a Discussion
Jasmine JalaludheenJasmine 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;
    }
  }
SFDC_SaurabhSFDC_Saurabh
try using <apex:inputField> instead of  <input> tag
ANUTEJANUTEJ (Salesforce Developers) 
Hi Jasmin,

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:
 
<apex:page controller="MyController" tabStyle="Account">
  <apex:messages/>
  <apex:form>
   <apex:pageBlock title="Hello {!$User.FirstName}!">
     This is your new page for the {!name} controller. <br/>
     You are viewing the {!account.name} account.<br/><br/>
     Change Account Name: <p></p>
     <apex:inputField value="{!account.name}"/> <p></p>
     Change Number of Locations:
     <apex:inputField value="{!account.NumberofLocations__c}" id="Custom_validation"/> 
         <p>(Try entering a non-numeric character here, then hit save.)</p><br/><br/>
     <apex:commandButton action="{!save}" value="Save New Account Name"/>
   </apex:pageBlock>
  </apex:form>
</apex:page>
 
public class MyController {
  Account account;

  public PageReference save() {
    try{
        update account;
       }
    catch(DmlException ex){
        ApexPages.addMessages(ex);
       }
    return null;
  }

  public String getName() {
    return 'MyController';
  }

  public Account getAccount() {
    if(account == null)
      account = [select id, name, numberoflocations__c from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
      return account;

  }
}
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
Abhishek BansalAbhishek Bansal
Hi Jasmine,

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.
Jasmine JalaludheenJasmine Jalaludheen
@Abhishek Bansal, Thank you for your response .I updated with <apex:pageMessages />,but still not working
@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
Jasmine JalaludheenJasmine Jalaludheen
Thank you for your response . I gave that and figured out that checkbox is making the issue. When I removed it it’s working , but I need the checkboxes to connect with a user profile .
Jasmine JalaludheenJasmine Jalaludheen
Hi Anutej , I figured it out that the checkbox ☑️ Part is making the problem.when I removed it it’s working fine, but I need those
Jasmine JalaludheenJasmine Jalaludheen
@Saurabh Agarwal Thank you for your response. I changed the code. Checkbox ☑️ portion we’re making the issue. When I removed it my page is working , but I need checkboxes to connect with the user profile. Any help.I think the format what I gave is the issue. 🙏🏻
Abhishek BansalAbhishek Bansal
Hi Jasime,

Please replace the below code:
<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>

-----------------------------------Replace with below---------------------------

<apex:inputCheckbox value="{!USer.Profile}" label="Doctor"/>
<apex:inputCheckbox value="{!USer.Profile}" label="Nurse"/>
<apex:inputCheckbox value="{!USer.Profile}" label="Intern Doctor"/>

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
Jasmine JalaludheenJasmine Jalaludheen
I gave like this .Thank you. I created a community ,now when a user registers he or she should be assigned a profile Id . When I try I am getting below error.My community is active only. Can you please help me with this. [image: ERROR] Error:That operation is only allowed from within an active site.