function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott.MScott.M 

Form Component Submit after Errors Failing.

Hi all,

 

I have a visulforce component with a form built into it. The component controller handles the form submission and all the fields in the form are required. The submit action saves the form and rerenders it. If all the fields are filled out and submitted the form is successfully saved a thank you message appears, otherwise the errors show up below the required fields that aren't filled out. The form works great if all the fields are filled in without any errors the first time. The problem is that if there is an error on the first submit and the errors are corrected the next submit doesn't save correctly. Here's the code:

 

 

public class LeadController extends ContentCore { public Lead newlead {get; set;} public Opportunity newop {get; set;} public String promotion_id {get; set;} public Promotion__c promotion {get; set;} public LeadController() { this.newlead = new Lead(); this.newop = new Opportunity(); this.CurrentPageName = 'Request More Information'; this.CurrentPageUrl = System.currentPageReference().getUrl(); this.newlead.LeadSource = 'Website'; String prefix = ''; if(Site.getPrefix() != null) { prefix = Site.getPrefix(); } if(this.last_page != null) { this.newlead.ReferencePage__c = System.currentPageReference().getHeaders().get('host')+prefix+this.last_page.Location__c; } else { this.newlead.ReferencePage__c = System.currentPageReference().getHeaders().get('host')+prefix+this.CurrentPageUrl; } this.promotion_id = System.currentPageReference().getParameters().get('promotion_id'); if(this.promotion_id != null && this.promotion_id != '' ) { this.promotion = [SELECT Id, Name, Price__c, Title__c, Description__c, End_Date__c, ImageId__c, External_Link__c FROM Promotion__c WHERE Id =: this.promotion_id]; this.newlead.Promotion__c = this.promotion_id; } } public String[] getTags() { return new List<String>{'Connect'}; } public PageReference save() { if(this.newlead.Email != null) { //check if the contact exists Contact[] contacts = [SELECT Id, AccountId, Account.Name FROM Contact WHERE Email =: this.newlead.Email]; if(contacts.size() > 0) { if(contacts[0].Account.Name == this.newlead.Company) { this.newop.AccountId = contacts[0].AccountId; this.newop.Name = 'Web Opportunity'; this.newop.Type = 'Other'; this.newop.StageName = 'Prospecting'; this.newop.CloseDate = System.today().addDays(30); this.newop.Description = this.newlead.Description; if(this.promotion != null) { this.newop.Promotion__c = this.Promotion.Id; } upsert newop; return null; } } } upsert newlead; return null; } public String getPriceString() { return this.formatDouble(this.promotion.Price__c.doubleValue(), 2); } public String formatDouble(Double num, Integer decimalplaces) { Double multiplier = Math.pow(10, decimalplaces); num = num*multiplier; Long rounded = Math.roundToLong(num); num = rounded/multiplier; String formated = Decimal.valueOf(num).format(); //add zeros if needed Integer dotIndex = formated.indexOf('.'); if(dotIndex < 0) { formated += '.'; for(Integer i=0; i<decimalplaces; i++) { formated += '0'; } } else { Integer needed = decimalplaces - formated.substring(dotIndex+1).length(); for(Integer i=0; i <needed; i++) { formated += '0'; } } return formated; } } <apex:component controller="LeadController" allowDml="true"> <apex:attribute name="CurrentPageUrl" type="String" required="true" description="The url of the current page" /> <div class="article-controls"> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td style="width:40px; height:24px;"> <div style="position: relative; height: 24px; width: 40px; background-color:#c1cb97;"> <div style="position: absolute; top:0; left:0; width: 40px;"> <div style="float: left;"><apex:image value="{!$Resource.tlcorner}"/></div> <div style="float: right;"><apex:image value="{!$Resource.trcorner}"/></div> <div class="clear"></div> </div> <div style="position: absolute; bottom:0; left:0; width: 40px;"> <div style="position: static; float: left;"><apex:image value="{!$Resource.blcorner}"/></div> <div style="position: static; float: right;"><apex:image value="{!$Resource.brcorner}"/></div> <div class="clear"></div> </div> <div text="Sign up for updates" style="margin:4px 0px 4px 12px; width: 16px; height: 16px; float: left; cursor: pointer" onmouseover="roll('signup_icon','{!$Resource.signupon}');" onmouseout="roll('signup_icon','{!$Resource.signup}');" onclick="if($('#signupblock').is(':visible')) {$('#signupblock').hide();} else {$('#signupblock').show();} return false;"> <a href="#"><img src="{!$Resource.signup}" id="connect_with_us" title="CONNECT With Us" alt="CONNECT With Us" /></a> </div> <div class="clear"></div> </div> &nbsp; </td> <td>&nbsp;<!-- <div style="padding-left: 10px; color: #A8B561; font-size: 9pt;">Click to signup for<br /> regular updates</div>--></td> <td style="width: 53px; height:26px;"> <div style="position: relative; height: 26px; width: 53px; background-color:#c1cb97;"> <div style="position: absolute; top:0; left:0; width: 53px;"> <div style="float: left;"><apex:image value="{!$Resource.tlcorner}"/></div> <div style="float: right;"><apex:image value="{!$Resource.trcorner}"/></div> <div class="clear"></div> </div> <div style="position: absolute; bottom:0; left:0; width: 54px;"> <div style="position: static; float: left;"><apex:image value="{!$Resource.blcorner}"/></div> <div style="position: static; float: right;"><apex:image value="{!$Resource.brcorner}"/></div> <div class="clear"></div> </div> <table> <tr> <td style="padding-top: 3px; padding-left: 6px;"> <apex:outputLink value="{!CurrentPageUrl+'&pdf=1'}"><img src="{!$Resource.print}" id="print_icon" style="curser: pointer;" title="Print" alt="Print" /></apex:outputLink> </td> <td style="padding-top: 3px;"> <apex:outputLink value="{!CurrentPageUrl+'&pdf=1'}"><img src="{!$Resource.download}" id="download_icon" title="Download" alt="Download" /></apex:outputLink> </td> </tr> </table> <div class="clear"></div> </div> </td> </tr> </table> <div id="signupblock" style="display:none;"> <apex:outputPanel id="connect_form"> <apex:outputPanel rendered="{!ISNULL(newlead.Id)}"> <apex:form > <input type="hidden" name="sfga" value="00D3000000008XR"/> <h1 style="padding-top: 20px; font-size: 10pt;"> CONNECT With Us </h1> <table> <tr> <td>First Name</td> </tr> <tr> <td><apex:inputField value="{!newlead.FirstName}" styleClass="contact-input-text" required="true" /></td> </tr> <tr> <td>Last Name</td> </tr> <tr> <td><apex:inputField value="{!newlead.LastName}" styleClass="contact-input-text" required="true" /></td> </tr> <tr> <td>Your email address</td> </tr> <tr> <td><apex:inputField value="{!newlead.Email}" styleClass="contact-input-text" required="true" /></td> </tr> <tr> <td>Organization</td> </tr> <tr> <td><apex:inputField value="{!newlead.Company}" styleClass="contact-input-text" required="true" /></td> </tr> <tr> <td>How can we help?</td> </tr> <tr> <td><apex:inputField value="{!newlead.Description}" styleClass="contact-input-text-area" required="true" /></td> </tr> </table> <br /> <apex:commandButton action="{!save}" value="Submit" rerender="{!$Component.connect_form}" />&nbsp;&nbsp;<input type="reset" name="Clear" value="Clear" /> <br /> <br /> </apex:form> </apex:outputPanel> <apex:outputPanel rendered="{!!ISNULL(newlead.Id)}"> Thank you for your interest. <br /> We will respond within 24 hours. </apex:outputPanel> </apex:outputPanel> </div> </div> <p>&nbsp;</p> </apex:component>

 

 

 

Scott.MScott.M

This got moved out of the Sites forum; however, this is happening in the Sites context. That is I'm including the form component in our Website.

 

I'm not sure if that makes a difference or not since it's all visualforce. Anyway hope someone can help me out in the none Sites forum. 

patrospatros

Scott,

 

Did you ever get a response to this issue? I seem to be having the same problem with a component that displays a list of records. I'm trying to enable paging on the list with a command button that sets the current list page and rerenders the list. I keep getting a Visualforce error screaming about a null value on rerender, which doesn't make sense to me if the page loads successfully the first time...