+ Start a Discussion
Arvind010Arvind010 

How to make the checkbox as required field using apex code?

Code:
<apex:page controller="spptc">
<br><b>Terms and Conditions</b><br><br>
<hr>
<center><u><b><font color="blue">Print Terms and Conditions</font></b></u></center><br><br>
<center><textarea rows="13" cols="100" readOnly="true">PLEASE READ CAREFULLY. These Terms and Conditions ("Terms") govern your access to and use of this Seagate Technology Web site ("Site"). Some content accessible through this site is subject to additional terms and conditions. To the extent that any provision of those additional terms and conditions conflicts with these Terms, those additional terms and conditions will prevail. IF YOU DO NOT AGREE WITH THESE TERMS, DO NOT USE THIS SITE. YOUR USE OF THIS SITE INDICATES YOUR ACCEPTANCE OF THESE TERMS.

GENERAL. Seagate does not warrant that the contents of this Site are error-free. Information on this Site may contain technical inaccuracies or typographical or other types of errors and may be changed or updated at any time without notice. Seagate may also make improvements or changes in the products or programs described on this Site at any time without notice. Seagate will use reasonable efforts to place accurate and up-to-date information on this Site but makes no warranty of its accuracy, completeness or timeliness. You acknowledge that your use of any information available through this site is at your own risk.

WARRANTY DISCLAIMER. THE MATERIALS ON THIS SITE ARE PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND EITHER EXPRESS OR IMPLIED. TO THE FULLEST EXTENT POSSIBLE UNDER APPLICABLE LAW, SEAGATE DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT OR OTHER VIOLATION OF RIGHTS. SEAGATE DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE, VALIDITY, ACCURACY, OR RELIABILITY OF, OR THE RESULTS OF THE USE OF, OR OTHERWISE RESPECTING, THE MATERIALS ON THIS SITE OR ANY SITES LINKED TO THIS SITE.

DEALER LOCATOR DISCLAIMER - Seagate offers Dealer Locator as an informational service only, it is not an endorsement or recommendation - implied or otherwise - of any of the listed companies. Each company listed is independent from Seagate and is not under Seagate's control; therefore, Seagate accepts no responsibility for and disclaims any liability from the actions of the listed companies. You should make your own independent evaluation before conducting business with any company. Dealer information on this site was believed accurate when posted; however it may change without our knowledge. Please contact webmaster@seagate.com with updated information.

LIMITATION OF LIABILITY. IN NO EVENT WILL SEAGATE BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THIS SITE, OR ON ANY OTHER HYPER LINKED WEB SITE, INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, LOST REVENUE, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

LINKS TO THIRD PARTY SITES. There are links on this Site that will permit you to travel to other, third-party sites over which Seagate has no control. These links are provided for your convenience only and your use of them is at your own risk. Seagate makes no representations whatsoever about the content of any of these other web sites, or about any of the links contained in the Web sites that you may access through this Site. Seagate does not endorse or accept any responsibility for the content, or use, of any such linked web sites.
 
DOWNLOADABLE SOFTWARE. There are inherent dangers in the use of any software available for downloading on the Internet, and Seagate cautions you to make sure that you completely understand the potential risks before downloading any of the software (including the potential infection of your system by computer viruses). You are solely responsible for adequate protection and backup of the data and equipment used in connection with any of the software and assume all risks associated with any downloaded software.

JURISDICTION AND GOVERNING LAW. This Site is maintained, controlled, operated and administered by Seagate from within the United States of America (U.S.). Seagate makes no representation that materials at this site are appropriate for use at locations outside of the U.S. and access to this Site from countries where its content or operation is illegal is prohibited. If you access this Site from a location outside of the U.S., you are responsible for compliance with all local laws. The use of this site, its content and these Terms is governed by the laws of the State of California, without regard to its conflict of laws provisions. Any legal proceeding arising out of the use of this Site, its content or these Terms must be brought in Santa Clara, California and must be brought within one year after the claim or cause of action arises or it is barred. By using this site, you irrevocably submit to the jurisdiction of the State and Federal courts located in Santa Clara, California. If for any reason a court of competent jurisdiction finds any provision of these Terms to be unenforceable, that provision will be enforced to the maximum extent permissible so as to effect the intent of these Terms, and the remainder of these Terms will continue in full force and effect.

INTERNATIONAL TRADE COMPLIANCE. The goods licensed or sold under this Agreement, and the transaction contemplated by this Agreement, which may include technology and software, are subject to the customs and export control laws and regulations of the United States ("U.S.") and may also be subject to the customs and export laws and regulations of the country in which the products are manufactured or received. Further, under U.S. law, the goods shipped under this Agreement may not be sold, leased or otherwise transferred to restricted countries, or used by a restricted end-user or an end-user engaged in activities related to weapons of mass destruction including, without limitation, activities related to designing, developing, producing or using nuclear weapons, materials, or facilities, missiles or supporting missile projects, or chemical or biological weapons.  You acknowledge that it is your responsibility to comply with and abide by those laws and regulations, and that any customer or vendor that you request Seagate to route product to directly has also been made aware of the associated export controls.

COPYRIGHT AND TRADEMARK. The copyright in all material provided on this Site is held by Seagate or by the original creator of the material. Except as stated in this paragraph, none of the material may be copied, reproduced, distributed, republished, downloaded, displayed, posted, framed or transmitted in any form or by any means, including, but not limited to, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Seagate or the copyright owner. Permission is granted to display, copy, distribute and download the materials on this Site for personal, non-commercial use only, provided that you do not modify the materials and that you retain all copyright and other proprietary notices contained in the materials. You also may not, without Seagate's permission, "mirror" any material contained on this Site on any other server. This permission terminates automatically if you breach any of these terms or conditions. Upon termination, you must immediately destroy any downloaded or printed materials. Any unauthorized use of any material contained on this Site may violate copyright laws, trademark laws, the laws of privacy and publicity, and communications regulations and statutes.

CONFIDENTIAL INFORMATION. You may be given access to Seagate confidential information through this site or links from this site. You may not disclose Seagate confidential information to any third party without the written consent of Seagate. You must protect Seagate confidential information with at least the same degree of care that is accorded to your confidential information, but in no event less than reasonable care. Seagate confidential information includes, but is not limited to - all non-public information regarding Seagate, its intellectual property or its products, quantity and prices of products purchased, design and development data, engineering details, CAD drawings, sales and marketing plans, unannounced products, any information marked as "confidential" or "proprietary" or similarly marked, or any information that, if disclosed, might be competitively detrimental to Seagate. You may enter into separate non-disclosure agreements with Seagate governing specific disclosures. To the extent the terms governing a specific disclosure are more restrictive than the terms in this paragraph, the more restrictive terms will control for the specific disclosure.

PASSWORD AND USER NAME. Access to some content accessible from this Site is password controlled. By registering for an account, a password and the right to use this site, you are certifying that you are an authorized representative of your company with the right to bind your company to these Terms (and any additional terms necessary for access to password controlled content) and that all information provided in the registration process is accurate and correct. You further certify that any purchase orders placed by you are with the full authority to bind your company and any information provided by you in using any of the services accessible through this site is true and accurate. Your user name and password are unique to you or your company. You are solely responsible for maintaining the confidentiality of your user name, password and access to your account. You are solely responsible for all activities that occur under your user name and password. You agree to notify Seagate immediately of any unauthorized use of your user name, password or account or any other breach of security. Seagate will not be liable for any loss that you may incur as a result of someone else using your user name, password or account, either with or without your knowledge. But you may be held liable for losses incurred by Seagate as a result of the misuse of your user name, password or account.

SUBMISSION OF INFORMATION OR MATERIALS. Except for the details of your product orders, and confidential or proprietary information or materials covered by an existing non-disclosure agreement - you agree that any information or materials that you submit to Seagate via this Site or any email links provided on this site will not be considered confidential or proprietary. By submitting information or materials to Seagate via this Site or email links provided in such information or materials, you represent that you have the authority to grant and in fact do grant to Seagate an unrestricted, irrevocable, worldwide, royalty-free license to use, reproduce, display, publicly perform, transmit and distribute such information and materials world-wide, in whole or in part, and you further agree that Seagate is free to use any ideas, concepts or know-how that you submit for any purpose.

EMAIL FROM SEAGATE. Seagate may from time to time send you email. You acknowledge that such emails are sent with your consent and permission.

ENTIRE AGREEMENT. These Terms represent the entire agreement relating to the use of the Site. Seagate's failure to enforce any right or provision of these Terms does not constitute a waiver of that right or provision. Seagate may revise these Terms at any time by updating this posting. Your continued use of this Site after the posting of any changes to these Terms constitutes your acceptance of those changes. To view the most current version of these Terms at any time, click on the "Terms of Use" hypertext link available on this Site.
</textarea></center><br>
<apex:form >
<center><apex:inputCheckbox id="box1" Required="true" ></apex:inputCheckbox><b>I accept these terms and conditions</b></center><br>
<center><apex:commandButton action="https://na2.salesforce.com/home/home.jsp" onClick="Dothecheck()" value="Submit" ></apex:commandButton>
<apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton></center>
</apex:form>
</apex:page>



 How to make the check box as required field using apex code?I tried with Required="true".But it is not working.The user should navigate to the next page only when the check box is checked.
Can anyone provide the solution?

dchasmandchasman
There are a couple of issues with your approach. First, client side validation for this kind of thing is basically useless - totally trivial to go around your check in any number of ways. Second the way you are using the action attribute on apex:commandButton is not going to hit the server and will there never invoke the server side requiredness checks.

I'll workup an example that shows how to handle this in a bit but one question I have for you is how you intend to insure that this affirmation page is always presented and presented once and only once since it appears that you are not persisting the results (e.g. in a custom object).?

Here is an example of how I would handle this:

Code:
<apex:page controller="spptc">
<br/><b>Terms and Conditions</b><br/><br/>
<hr/>
<apex:form id="theForm">
    <apex:pageMessages />
    <center><u><b><font color="blue">Print Terms and Conditions</font></b></u></center><br/><br/>
    <center><textarea rows="1" cols="100" readOnly="true">PLEASE READ CAREFULLY. These Terms and Conditions ("Terms") govern your access...</textarea></center><br/>
    <center><apex:inputCheckbox id="box1" value="{!accepted}" required="true"/><b>I accept these terms and conditions</b></center><br/>
    <center>
        <apex:commandButton action="{!acceptTerms}" value="Submit" rerender="theForm"/>
        <input type="button" value="Cancel" class="btnClass"/>
    </center>
</apex:form>
</apex:page>

 
Code:
public class spptc {
    public boolean accepted { get; set; }

    public PageReference acceptTerms() {
        if (accepted) {
            return new PageReference('/home/home.jsp');
        } else {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, 'You must accept the Terms and Conditions to continue'));
            return null;
        }
    }


    public PageReference cancel() {
        // Not sure what you want to do here???
return null; } }


Message Edited by dchasman on 07-04-2008 11:03 AM
Arvind010Arvind010
I am getting the following error when i click on the Submit button

System.NullPointerException: Attempt to de-reference a null object

dchasmandchasman
I am not seeing that error with my demo page/controller - I did make one modification to the controller to return a relative page ref to /home/home.jsp instead of an absolute ref.
Arvind010Arvind010
I tried the code what you provided me in the previous reply.I am getting error.I did not understand the following line in the code
public boolean accepted { get; set; }

I have one more question.
How to display a pop up window or message box using apex code in visualforce page after clicking a button?
Arvind010Arvind010
I used the code what you have provided.The problem what i am facing is, when i click on Submit button without
checking the checkbox,it is not navigating to the next page,it remains in the same page without displaying the
Warning message.When i select the Checkbox,it is working properly.

Can you please provide me the solution?