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
SabrentSabrent 

Visualforce Page Redirect to Thankyou Page within Iframe

This visualforce page is referenced in Sites inside my Salesforce Org. The site domain is iframed inside the company website.

On form submit, there should only be paragraph text saying "Thank you for Submitting the form, A team member will contact you soon." as a completed action and not redirect to any other page.

This is the code I have, but it redirects to the new page within an iframe, which looks ugly and confusing.  A simple Thanks you message on submit without navigating to a new page is what i am after. 

Can someone please guide. ? 
 
<apex: page ... >
      <paex:form>        
         <apex:commandButton onclick="validation();return false;" value="submit" reRender="frm" />
      <apex:form>
   <apex:page>



Class 

 Public PageReference savelead(){
         if (this.validateRecaptcha() == false) {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'Please re-enter the RECAPTCHA'));
            return null;
         }else{
            lead.LeadSource = 'Web';
            lead.LastName = lastname;
            lead.Company = company;
            insert lead;
        
            PageReference reRend = new PageReference('https://www.companysite.com/node/111/done?sid=8888&token=8888888880d9c68282306d7af9f8888');
            reRend.setRedirect(true);
            return reRend;
    
          }
       }


 
Best Answer chosen by Sabrent
Vishwajeet kumarVishwajeet kumar
Hello,
I think you can use a variable in controller which can allow to display/render/hide Thank you message on Page, set it to true on successful submit in method.

Something like this : 
Controller Variable  -  public boolean m_DisplayThankYouMsg{get;set;}

Method : 

Public PageReference savelead(){
if (this.validateRecaptcha() == false) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'Please re-enter the RECAPTCHA'));
return null;
}else{
lead.LeadSource = 'Web';
lead.LastName = lastname;
lead.Company = company;
insert lead; 
m_DisplayThankYouMsg = True;
return Null;
}
}


On Page : use <apex:pageMessage> component to put message and display only when m_DisplayThankYouMsg == True.

<apex:pageMessage summary="Thank you for Submitting the form, A team member will contact you soon." severity="confirm" strength="3" rendered="{!m_DisplayThankYouMsg == True}"/>

Use same variable (on rendered) to hide other components on page with {!m_DisplayThankYouMsg != True} when in Thank you page mode.


Thanks