21298 Posts in 5735 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 168 Views |
-
Variables only displaying when page is refreshed

1 November 2012 at 11:30pm
Hi,
I asked this in a different section, but haven't received a reply in almost a week.
http://www.silverstripe.org/data-model-questions/show/21293Since asking, I have modified it a bit, but still only works when refreshing the page.
I am trying to get a variable from various google location ads to change the phone number depending on the ?number=xxx from the ad.
Currently the number displays a default value unless the page is refreshed, then the variable is displayed.
I need it to display the number without the need for a refresh.Is there a better way of doing this that will display the variable number without the need for a page refresh?
In page.ss
<% if phonenumber %>$phonenumber <% else %>0800 xxx xxx<% end_if %>
In page.phppublic function Phonenumber() {
if (!isset($_SESSION['number']))
{
$phonenumber = $_GET['number'];
$_SESSION['number'] = $phonenumber;
}
return strip_tags (Session::get ('number'));
}
Any advice or pointers are massively appreciated. -
Re: Variables only displaying when page is refreshed

2 November 2012 at 11:24am
You might be better writing that function as
$number = Session::get('number');
if($get = $this->request->getVar('number')) {
$number = $get;
Session::set('number', $get);
}return Convert::raw2xml($number);
-
Re: Variables only displaying when page is refreshed

3 November 2012 at 12:54am
Willr, thanks. That has fixed all my woes.
Except the admin section is white screening with no error being thrown.I created a different page type and put this function on there instead of page.php and the admin section is accessible again.
One more question, is it possible to use a field in the CMS that can be used as the variable?
I.E.$fields->addFieldToTab('Root.Content.Main', new TextField('StaticNumber'), 'Content');
is this possible?
| 168 Views | ||
|
Page:
1
|
Go to Top |


