commandButton action on form submit not calling method on controller

See the code below, when I click Agree I woudld expcet doSave to be called on the controller, but when I debug, I do not see the log message and I only stay on the same page.

Things I have tried:
– removing disabled=true
– adding/removing immediate=true
– adding/removing all javascript (not shown here, since I removed)
– adding a visualforce element to the form (since it might be trying to outsmart me)

None of these worked.

Here is my controller:

public with sharing class TandCAgreeController {

public _Operating_Terms_And_Condition__c tAndC {get; set;}
public TLD__c tld {get; set;}

public TandCAgreeController() 
{
    System.debug('got to contstructor');
    tAndC = [select terms_and_condition_text__c from _Operating_Terms_And_Condition__c where is_active__c = true];
    tld = new TLD__c();
}

public PageReference doSave() { 
    // save the ref to the agrement they agreed to

    System.debug('got to save method on tandcagree');

    PageReference pageRedirect = Page.StartPage;

    return pageRedirect;
}

}

Here is my page:

<apex:page controller="TandCAgreeController" id="TandCAgreePage" docType="html-5.0" showHeader="false">
<apex:composition template="{!$Site.Template}">

<apex:define name="body">

<div class="container">

<h2>Please review and agree to the terms and conditions. There is an agree check box at the bottom that will allow you to agree and continue when you check it.</h2>
<br></br>

<br></br>
    <apex:pageMessages />   

            <apex:form >

                <div class="control-group">
                    <label class="control-label">Subject:</label>
                    <div class="controls">
                      <div id="" style="overflow-y: auto; height:100px; border: 1px solid #DDDDDD;">
                            <apex:outputtext value="{!tAndC.terms_and_condition_text__c}" escape="false"></apex:outputtext>
                            <br/>
                            <div ><span style="font-weight:bold;">Check to Agree:</span>&nbsp;<input type="checkbox" name="agree" value="agree" id="agreement-checkbox"/> </div>
                      </div>
                    </div>                              
                </div>
            <div class="control-group">
                <apex:commandButton action="{!doSave}" value="Agree" disabled="true" Styleclass="btn btn-small" immediate="true"/>
            </div>
    </apex:form>
    </div>
</apex:define>
</apex:composition>
</apex:page>

Answer

<apex:commandButton action="{!doSave}" value="Agree" disabled="true" Styleclass="btn btn-small" immediate="true"/>

I see from the above code you have disabled=true and hence the issue .Please remove and retry .Once a button is disabled the form wont be submitted

Update:

Another reason is since it has a template i fear you have two forms and that may have caused the issue of method not calling

Attribution
Source : Link , Question Author : Joelio , Answer Author : Mohith Shrivastava

Leave a Comment