Hi I have a consent statement and the user needs to check the box before registering. How can I refer the checkbox in the controller class and check the status of the checkbox to show an error message if checkbox is not checked.
VF Page
<apex:page controller="showUser" >
<html>
<head>
<title>Program Registration</title>
</head>
<body>
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Registration" >
<apex:inputCheckbox id="chkboxiagree"/>
I agree statement
<apex:pageBlockButtons >
<apex:commandButton action="{!saveRecord}" value="Register"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</body>
</html>
</apex:page>
Controller class
public class showUser {
public String userName{set;get;}
public List<Contact> storeDetails{set;get;}
public Boolean chkboxiagree {set;get;}
public static void saveRecord()
{
showUser su = new showUser();
try
{
if (su.chkboxiagree == false) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please agree to the consent statement'));
//return null;
}
Event_Registrations__c event = new Event_Registrations__c();
su.userName= UserInfo.getUserEmail();
system.debug(su.userName);
su.storeDetails = [select Store__c, AccountId, Account.Name from contact where Member_COMMUNITY_Username__c like :su.userName];
event.Store_No__c = su.storeDetails[0].Store__c;
event.Account__c = su.storeDetails[0].AccountId;
event.Program_Event__c = 'a1G3D000001Re07UAC';
insert event;
Account accountData = [select Id from Account where ID = :event.Account__c limit 1];
accountData.Registered_for_MedSask__c = true;
update accountData;
}
catch(Exception e)
{
System.debug('An unexpected error has occurred: ' + e.getMessage());
}
}
}
Can some one help me in this?