You need to sign in to do that
Don't have an account?
Custom Contact Form - actionFunction not setting variables
I'm trying to create a simple contact form that e-mails the form contents to a specific address. The e-mail is being sent just fine, but the variables I'm using in my controller code aren't being set by the actionFunction prior to sending out the e-mail. Here's the code for form:
<apex:outputPanel id="contactFormArea"> <apex:form id="emailform" rendered="{!Not(sent)}" > <table width="100%" border="0" cellspacing="0" cellpadding="4" class="css3Box"> <tr> <td width="23%" align="right" valign="top" class="page-content">Name:</td> <td width="77%" align="left" valign="top"><apex:outputText value="{!yourname}" id="yourname" styleClass="page-content" /></td> </tr> <tr> <td align="right" valign="top" class="page-content">E-Mail:</td> <td align="left" valign="top"><apex:inputText value="{!youremail}" id="youremail" maxlength="80" size="40" styleClass="page-content" /></td> </tr> <tr> <td align="right" valign="top" class="page-content">Phone:</td> <td align="left" valign="top"><apex:inputText value="{!yourphone}" id="yourphone" maxlength="80" size="40" styleClass="page-content" /></td> </tr> <tr> <td align="right" valign="top" class="page-content">Category:</td> <td align="left" valign="top"> <apex:selectList id="subject" size="1" > <apex:selectoption itemLabel="Site Issue/Problem" itemValue="Problem"></apex:selectoption> <apex:selectoption itemLabel="Question" itemValue="Question"></apex:selectoption> </apex:selectList> </td> </tr> <tr> <td align="right" valign="top" class="page-content">Message:</td> <td align="left" valign="top"><apex:inputTextarea value="{!body}" id="body" rows="6" cols="40" styleClass="page-content" /></td> </tr> <tr> <td align="right" valign="top"> </td> <td align="left" valign="top"><apex:commandButton value="SEND" id="sendButton" onclick="sendEmail();"/></td> </tr> </table> <apex:actionFunction name="sendEmail" action="{!sendIt}" reRender="contactFormArea" immediate="true"> <apex:param name="youremail" assignTo="{!youremail}" value=""/> <apex:param name="yourphone" assignTo="{!yourphone}" value=""/> <apex:param name="subject" assignTo="{!subject}" value=""/> <apex:param name="body" assignTo="{!body}" value=""/> </apex:actionFunction> </apex:form> <apex:outputPanel rendered="{!(sent)}"> <table width="100%" border="0" cellspacing="0" cellpadding="4" class="css3Box"> <tr> <td>e-mail sent</td> </tr> </table> </apex:outputPanel>
</apex:outputPanel>
And here's the controller code:
// Constructor public MIQ_ContactExtensionController(ApexPages.StandardController stdController) { sent = false; yourname = userInfo.getName(); } public PageReference sendIt() { params = ApexPages.CurrentPage().getParameters();
system.debug('+++++++++++++++++++++++++++++++++++++++++++Params: '+params);
// Define the email Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] { 'steve.manatt@acxiom.com' }; if (yourphone == '') { yourphone = 'N/A'; } // Sets the paramaters of the email email.setSubject( subject ); email.setToAddresses( toAddresses ); email.setPlainTextBody( 'From: ' + yourname + ' (' + youremail + ') \n\n\r' + 'Subject: ' + subject + '\n\n\r' + 'Message: ' + body + '\n\n\r' ); // Sends the email Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); sent = true; system.debug('++++++++++++++++++++++++++++++++++++e-mail: '+youremail); return null; }
The debug logs for "params" show the form values being sent in the form of "jcref.emailform.youremail=test@test.com"; however, the param variable "youremail" is blank.
This really doesn't seem like something very hard, but I've spent two+ days on it. I sure hope someone out there can spot the problem.
Thanks in advance.
I figured it out. The javascript function needed to include the fields as parameters when calling the actionFunction.