I am new in the Salesforce coding. I have two pages. On one page I am filling the data and saving it. After click on Save button, I want to see the exact same data which I filled on last page. This is my code.
When I click on Save button first time, it stay on the same page. When I click on Save button again, it throws a message "The page you submitted was invalid for your session. Please refresh your page and try again."
---------------------------------------FIRST VF PAGE-----------------------------------------
<apex:page controller="VisitorRegistration" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock title="Visitor Detail Page" mode="edit">
<apex:pageBlockSection title="Please fill the visitor information " collapsible="true">
<apex:inputField value="{!visitor.Name}"/> <br/>
<apex:pageMessages id="showmessage">
</apex:pageMessages><br/>
<apex:inputField value="{!visitor.CountryName__c}"/><br/>
<apex:inputField value="{!visitor.Passport_Number__c}"/><br/>
<apex:inputField value="{!visitor.Covid_19_Symtomp__c}"/><br/>
<apex:inputField value="{!visitor.SendToQuarantineCenter__c}"/> <br/>
<apex:inputField value="{!visitor.CanVisitorGoToHome__c}"/><br/>
<apex:inputField value="{!visitor.Quarantine_Cetner__c}"/><br/>
<apex:inputField value="{!visitor.PatientEntryDate__c}"/><br/>
<apex:inputField value="{!visitor.Patient_Exit_Date__c}"/><br/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!saveV }" value="Save" reRender="true" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
-----------------------------------------APEX CODE--------------------------------------------------
public class VisitorRegistration {
public Visitor__c visitor{get;set;}
public VisitorRegistration()
{
visitor= new Visitor__c();
}
public void getVisitorID()
{
Id id = apexpages.currentpage().getparameters().get('Id');
}
public PageReference saveV()
{
If(visitor.Name==null || visitor.Name=='')
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));
}
INSERT visitor;
pagereference pr = new pagereference('/apex/VisitorRegistrationViewPage?id='+Visitor__c.id);
pr.setRedirect(false);
return pr;
}
}
---------------------------------------SECOND VF PAGE----------------------------------------------------
<apex:page controller="VisitorRegistration" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock title="Visitor Detail Page">
<apex:pageBlockSection title="Visitor Information " collapsible="true">
<apex:outputField value="{!visitor.Name}"/> <br/>
<apex:outputField value="{!visitor.CountryName__c}"/><br/>
<apex:outputField value="{!visitor.Passport_Number__c}"/><br/>
<apex:outputField value="{!visitor.Covid_19_Symtomp__c}"/><br/>
<apex:outputField value="{!visitor.SendToQuarantineCenter__c}"/> <br/>
<apex:outputField value="{!visitor.CanVisitorGoToHome__c}"/><br/>
<apex:outputField value="{!visitor.Quarantine_Cetner__c}"/><br/>
<apex:outputField value="{!visitor.PatientEntryDate__c}"/><br/>
<apex:outputField value="{!visitor.Patient_Exit_Date__c}"/><br/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>