0

I am fairly new to Salesforce and VisualForce. I've been asked to have my visual force input page do validation on a field. Based on information that I have gleamed from other posts, I tried to come up with a solution, but I can't seem to get it to work. My intent is to validate a field called 'offenderCDCRNoField'.

When I click on 'Send' nothing seems to happen. I'd sure welcome any suggestions on where I went wrong with my implementation of a call to a function called 'Validate'. If we pass the validation, I want to do a re-render with a confirmation page. If it fails the validation, I want it to give me an alert indicating a problem. But now, nothing happens at all.

    <apex:page controller="OmbudsmanRequest" sidebar="false" showHeader="false" docType="html - 5.0">
<!-- Component Name: OmbudsmanRequestController.vfp      -->
<!-- Date created:   11/19/2018                          -->
<!-- Created by:     Eric Lynn Anderson                  -->
<!--                                                     -->
<!-- Component Desc: The following method code defines   -->
<!--                 the visual force page that allows   -->
<!--                 people to enter requests to the     -->
<!--                 ombudsman division. It will then    -->
<!--                 call Apex code to subsiquently send -->
<!--                 an email relaying the information   -->
<!--                 to a Salesforce service which will  -->
<!--                 then consume it.                    -->
<!-- Copywrite:  This component is for the exclusive     -->
<!--             use of the California Department of     -->
<!--             Corrections and Rehabilitation (CDCR),  -->
<!--             its employees and divisions. Any other  -->
<!--             use of this component by any other      -->
<!--             entity without the express written      -->
<!--             consent of CDCR management is           -->
<!--             is strictly prohibited.                 -->

    <apex:outputPanel id="rerenderThis">
    <apex:form >
        <apex:pageBlock title="Contact Us" rendered="{!NOT(Hideshow)}">
             <H3>
              Issue resolution and support 
            </H3>
            <br />    
            <br />    
            If you have not been able to resolve an inmate/juvenile issue with a CDCR prison or juvenile facility, contact the Office of the Ombudsman.
            <br />    
            <br />    
            <p><em><strong>The contact information on this page is specific to the Office of the Ombudsman.</strong></em></p>
            <br /> 
            <a href="https://www.cdcr.ca.gov/contactus.html" target="_blank">Visit the main CDCR Contact page</a> if you have questions not directly pertaining to resolving an inmate/juvenile issue with a CDCR prison or juvenile facility.</em> <em>For information on  parole centers see the <a href="https://www.cdcr.ca.gov/Parole/" target="_blank">Division of Adult Parole Operations section</a>. </em></p>
            <H3>
                Please contact us by submitting a request:
            </H3>
            <br />    
            Please complete and submit the form below. All fields are required. 
            <br />    
            <br />  
        <!-- You can not use the required attribute, as this will require Salesforce logon -->    
        <apex:outputLabel value="Your First Name:" for="firstNameField"/>
        <br />
        <apex:inputText id="firstNameField" value="{!firstNameField}"/>
        <br />
        <br />
        <apex:outputLabel value="Your Last Name:" for="lastNameField"/>
        <br />
        <apex:inputText id="lastNameField" value="{!lastNameField}"/>
        <br />
        <br />
        <apex:outputLabel value="Your Phone Number: (Include area code)" for="phoneNoField"/>
        <br />
        <apex:inputText id="phoneNoField" value="{!phoneNoField}"/>
        <br />
        <br />
        <apex:outputLabel value="Your Email Address:" for="emailAddressField"/>
        <br />
        <apex:inputText id="emailAddressField" value="{!emailAddressField}"/>
        <br />
        <br />
        <apex:outputLabel value="Your Relationship to the Offender:" for="offenderRelationshipField"/>
        <br />
        <apex:inputText id="offenderRelationshipField" value="{!offenderRelationshipField}"/>
        <br />
        <br />
        <apex:outputLabel value="Offender's CDCR Number:" for="offenderCDCRNoField"/>
        <br />
        <apex:inputText id="offenderCDCRNoField" value="{!offenderCDCRNoField}"/>
        <br />
        <br />
        <apex:outputLabel value="Offender's First Name:" for="offenderFirstNameField"/>
        <br />
        <apex:inputText id="offenderFirstNameField" value="{!offenderFirstNameField}"/>
        <br />
        <br />
        <apex:outputLabel value="Offender's Last Name:" for="offenderLastNameField"/>
        <br />
        <apex:inputText id="offenderLastNameField" value="{!offenderLastNameField}"/>
        <br />
        <br />
         <apex:outputLabel value="Location of Offender:" for="InstitutionList"/>
        <br />
        <apex:selectList value="{!institutions}" multiselect="false" size="5" id="InstitutionList">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>
        <br />
        <br />
        <apex:outputLabel value="Brief description of issue:" for="issueDescField"/>
        <br />
        <apex:inputTextArea id="issueDescField" value="{!issueDescField}" rows="5" cols="50"/>
        <br />
        <br />
       <apex:outputLabel value="Brief overview of efforts made by you, and/or the offender, to resolve the issue:" for="resolutionEffortField"/>
        <br />
        <apex:inputTextArea id="resolutionEffortField" value="{!resolutionEffortField}" rows="5" cols="50"/>
        <br />
        <p>Click 'Submit' when complete!</p>
        <apex:commandButton value="Submit" id="submitButton" action="{!send}" onclick="return validate();" rerender="rerenderThis" />

            <br />    
            <br />    
            You may also contact the Office of the Ombudsman by calling (916) 445-1773 or writing to:
            <br />    
            <br />    
            California Department of Corrections and Rehabilitation
            <br />    
            Office of the Ombudsman
            <br />    
            1515 S Street
            <br />    
            Sacramento, CA 95811        
        </apex:pageBlock>
        <apex:pageBlock title="Case Submitted" rendered="{!Hideshow}">
             <p>
                Thank you for contacting the California Department of Corrections and Rehabilitation, 
                Office of the Ombudsman, and for bringing your concerns to our attention. Please 
                allow this confirmation to serve as acknowledgement of your submission. You may 
                expect a member of our staff to contact you and we appreciate your patience while
                we research your concerns. 
                <br/> 
                <br/> 
            <apex:outputLabel value="First Name: " for="firstNameField" style="font-weight:bold"/>
            <apex:outputText value="{!firstNameField}"/>
                <br/> 
            <apex:outputLabel value="Last Name: " for="lastNameField" style="font-weight:bold"/>
            <apex:outputText value="{!lastNameField}"/>
                <br/> 
            <apex:outputLabel value="Email: " for="emailAddressField" style="font-weight:bold"/>
            <apex:outputText value="{!emailAddressField}"/>
                <br/> 
            <apex:outputLabel value="Phone: " for="phoneNoField" style="font-weight:bold"/>
            <apex:outputText value="{!phoneNoField}"/>
                <br/> 
                <br/> 
            <apex:outputLabel value="Concerning Offender:" style="font-weight:bold"/>
                <br/> 
            <apex:outputText value="{!offenderFirstNameField}"/>
                 <br/>
            <apex:outputText value="{!offenderLastNameField}"/>
                <br/> 
            <apex:outputText value="{!offenderCDCRNoField}"/>
                <br/> 
            <apex:outputText value="{!institutions}"/>
                <br/> 
                <br/>
            <apex:outputLabel value="Issue Description:" for="issueDescField" style="font-weight:bold"/>
                <br/> 
            <apex:outputText value="{!issueDescField}"/>
                <br/> 
                <br/> 
            <apex:outputLabel value="Efforts to resolve:" for="resolutionEffortField" style="font-weight:bold"/>
                 <br/> 
           <apex:outputText value="{!resolutionEffortField}"/>
                <br/> 
                <br/> 

                Thank you for contacting the Office of the Ombudsman.  

            </p>

</apex:pageBlock>

    </apex:form>

<script>
function validate(){
    val = document.getElementById('{!$Component.thepage.theForm.offenderCDCRNoField}').value;
    var cdcrno_pattern = /^\D{1}\w{1}\d(4)$/;
    if ('form.offenderCDCRNoField.value.match(cdcrno_pattern)){
        choice = confirm('Please enter the CDCR number. \nFormat: xx9999 or x99999.');
    if (choice==true)
        return false;
    else
        return true;
    }
    return true;
}
</script>
    </apex:outputPanel>

</apex:page>
  • Have you tried creating a validation rule directly on the object instead? – Sebastian Kessel Mar 20 at 21:54
  • P.S. it's "copyright," not "copywrite." Also, you probably shouldn't be including such notations on a public forum, as you're basically saying you don't have permission to post this code. – sfdcfox Mar 21 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.