[SalesForce] Passing Picklist Values to Controller with InputField in VisualForce

I'm new to VisualForce and trying to figure out how to pass the values a user selected from a birthday picklist into my controller. The picklists are fields of my Contact object and one is dependent on the other (the month selected determines the days selectable). Whenever I try to submit a value, nothing shows up (I have at least one contact for every birthday). How do I do this correctly?

Here is my VisualForce code:

<apex:page controller="BirthdayController">
    <apex:form >
        <h3>Enter Your Birthday:</h3>
        Month: <apex:inputField value="{!c.Month__c}"/>
        Day: <apex:inputField value="{!c.Day__c}"/>
        <apex:commandButton value="Submit" action="{!submit}"/>
        <apex:pageBlock title="Birthdays">
            <apex:pageBlockTable value="{!Birthdays}" var="b">
                <apex:column value="{!b.FirstName}"/>
                <apex:column value="{!b.LastName}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

And here's my controller code:

public class BirthdayController
{
    public Contact c {get; set;}
    public String bday;
    public void submit()
    {
        bday = c.Month__c + '/' + c.Day__c;
    }
    public List<Contact> getBirthdays()
    {
        List<Contact> results = [SELECT FirstName, LastName FROM Contact WHERE Birthday__C = :bday];
        return results;
    }
}

EDIT: Basically what I'm trying to do is make it so that a user can select a date using the picklists and have all the contacts with matching birthdays show up. I know I could do this by manually creating a populating a selection list, but I want to use the contact fields because they are dependent. Is what I'm trying to do possible?

Best Answer

You need to create the Contact object whose fields your page sets, for example in your controller's constructor:

public BirthdayController() {
    c = new Contact();
}
Related Topic