I'm trying to pass the value from a page variable to another page (both using different controller) without using parameters.
This is what am working on that.
I have user search page with input field.
It's a user search,If the user not found in the search, i provide the link below and says that click here to register. The input field search value which i have give should be populated in the Another page.
To achieve this how to pass the value, Please help me on this.
Page 1:
<apex:page controller="SearchPageController" sidebar="false" showHeader="false" docType="html-5.0" cache="false" id="pg">
<style>
.slds-scope .slds-box {
padding: 2rem;
border-radius: 1.25rem;
border: 4px solid #a4bfe4;
width: 100%;
padding-left: 55px;
padding-right: 55px;
margin: 0 auto;
background-color: #fdfdfd;
}
.searchBox{
border: 2px solid #a4bfe4;
border-radius: 1.25rem;
padding-left: 5px;
width: 25%;
height : 30%;
}
.controls{
background-color:#fdfdfd;
}
</style>
<apex:form id="fm">
<script>
function conRec () {
// alert('conRec');
var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
var SearchVal = document.getElementById('pg:fm:pb:SearchValue').value;
alert(SearchVal);
if(SearchVal.match(pattern)){
alert('true');
}else{
alert('False');
}
}
</script>
<apex:slds />
<apex:pageBlock id="pb" >
<div class="slds-scope slds-box">
<apex:outputPanel >
<div id="formBlock">
<div id="showErrorMsgbuserName">
<div class="slds-form-element">
<div class="slds-align_absolute-center">
<!--- <apex:input value="{!searchBoxstring}" id="SearchID" styleClass="searchBox"/> --->
<apex:input value="{!searchBoxstring}" styleClass="searchBox" id="SearchValue" />
<apex:commandButton value="Search" onClick="conRec()" action="{!display}" >
</apex:commandButton>
<div class="slds-hide slds-form-element__help" id="error-message-userName">This field is required</div>
</div>
</div>
</div>
</div>
<apex:pageMessages id="Error" escape="false" />
<br/>
<br/>
<apex:dataTable value="{!result}" var="con" border="1" cellpadding="5" cellspacing="4" bgcolor="lightblue">
<apex:column value="{!con.Name}" styleClass="controls">
<apex:facet name="header">Name</apex:facet>
</apex:column>
<apex:column value="{!con.Email}" styleClass="controls">
<apex:facet name="header">Email</apex:facet>
</apex:column>
<apex:column value="{!con.Phone}" styleClass="controls">
<apex:facet name="header">Phone</apex:facet>
</apex:column>
</apex:dataTable>
</apex:outputPanel>
</div>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class SearchPageController {
public string searchboxstring{get; set;}
public String Email{get;set;}
public list<contact> result {get; set;}
public SearchPageController()
{
result = new list<Contact>();
}
public pagereference display(){
system.debug('searchboxstring1-->' + searchboxstring);
Email = searchboxstring;
result=new List<Contact>();
system.debug('searchboxstring-->' + searchboxstring);
Email = searchboxstring;
system.debug('Email-->' + Email);
//result=[select ID, Name, Email, Phone from Contact where FirstName like :searchboxstring or LastName like :searchboxstring or Email like :searchboxstring or Phone like :searchboxstring];
result=[select ID, Name, Email, Phone from Contact where Name like :searchboxstring or Email like :searchboxstring or Phone like :searchboxstring];
system.debug('result-->' + result.size());
if (result.size() < 1) {
ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'No data Found' + '<a href='+ System.URL.getSalesforceBaseUrl().toExternalForm()+ '/apex/Registration' + '>Click Here</a>' + 'to Register Or '+ '<a href='+ System.URL.getSalesforceBaseUrl().toExternalForm()+ '/apex/Registration' + '>Click Here</a>' +' to Send Email to Register'));
}
return null;
}
}