I am loading a form in an overlay. The overlay has a separate controller and action to the page that invokes the overlay.
On form submit, if successful, I simply want to reload the referring page that the overlay was loaded from. I can get the referring page to load, but it places the content inside the overlay.
header("Location: www.example.com", true, 302);
does not work.
Using the URL helper like this:
$url = $_SERVER['HTTP_REFERER'];
redirect($url);
Also does not work. Every time it loads in the overlay. I am sad because of it.
You can use this code to refresh in codeigniter:
redirect($_SERVER['REQUEST_URI'], 'refresh');
it should work!
This one is more simple
redirect($this->uri->uri_string());
Unfortunately, using header to refresh/redirect will only reflect the changes in the container that is displaying the PHP page.
To refresh the parent page (i.e. the page that is displaying the overlay itself), you will need to do it on the client-side using Javascript. These questions should help you get on the right path:
Redirect parent window from an iframe action
PHP "header (location)" inside IFRAME, to load in _top location?
You can use this code to refresh in codeigniter:
redirect($_SERVER['REQUEST_URI'], 'refresh');
Hope this helps.
You do not have to supply additional two arguments for header. Just use this pattern:
header('Location: www.somewhere.com');
Also, check out this article about a similar matter:
Redirect with CodeIgniter
redirect(site_url(strtolower(__CLASS__)));
It's just
redirect('/some_url', 'refresh');
First load under constructor method like as:
function __construct()
{
parent::__construct();
$this->load->library('user_agent');
}
After inserting or update add this method it will work fine.
redirect($this->agent->referrer());
This one is more simple for everone :)
location.reload()
Related
I have 2 PHP pages. In the first page, I am clicking a button which redirects to another file via <a> tag and does its work(sending mail). but now I want once that page functionality is done it should come to the previous page without any user action. How can I do that?
include once is not the solution since it just calls other php. I need to come back to the same page, however.
Try with this
header('Location: ' . $_SERVER['HTTP_REFERER']);
You can use :
header('Location: '.$_SERVER['HTTP_REFERER']);
Here is the solution you can go back to the previous page using javascript.
There is one object in DOM called History you can use that in onload event:-
forexample https://www.w3schools.com/jsref/met_his_go.asp
window.History.go(-1);
As per my client need , redirect the page without anchor tag and refresh page ,
and change the URL as per page appearance. I don't know any idea about this.
I can use ajax for page content. but I don't know the URL change option without
page refresh or redirect. how can I do this with ajax j-query. Any one guide me for this issue.thanks advance
sample url
www.samplesite.com/contact.php -> without anchor tag. and page refresh this url need to work on php.
I think you are looking for info about the new HTML5 History API ( pushstate ), this link has a detailed tutorial.
http://diveintohtml5.info/history.html
You can do this using below function.
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
You can use the following javascript functions
window.location.assign('http://www.samplesite.com/contact.php'); // keeps the current page in browser history
window.location.replace('http://www.samplesite.com/contact.php'); // replaces the current page in browser history
window.location = 'http://www.samplesite.com/contact.php'; // the same as assign() and is backward compatible even with the oldest browsers
jsfiddle
I am currently working on the project that have 2 php files category.php and product.php.
In category.php file i put a link shown below.
click here
I have the following js function called on the body onload in the product.php page.
<body onload="font_select(1760,'No',239)">
When users click on the link then they will be redirect to product.php file where the body onload function is called.this function is working fine.
My question is i need to call this function only once when the user enter in product.php page.currently this function is called on page reload also.
How would i call this function only once ? Thanx In Advance.
The most efficient way will be, use Cookies
(It's a little kludgy, but you could check document.referrer in font_select)
well that's wrong, turns out at least in firefox the referrer does not change apparently when the page is refreshed.
You may want to have a look at this question, where they handle detecting refresh using a cookie, however you should know that is really just a check if the page has been accessed before so it won't work unless you also clear that cookie on detecting a click on the link from your category.php page.
Go for javascript cookies
well to track whether the function is called or not, you could use javascript cookie. Like say you set a cookie with any name, say functioncalled with value 0 initially, when user goes to product page, check this cookie. If value is 0, then call a function then set the value of cookie to 1, next time when page is reloaded the function will not be called.
I have a button on my home page which leads to a signup/login page. The signup/login page is just a page in views/pages/signup.ctp and as such doesn't have an action associated with it.
I want it so if a user is already logged in when they're on the homepage and they click my signup/login button, instead of taking them to the signup/login page it redirects them to another action. But since the signip/login page doesn't have an action I don't know where to do the check and redirect. Is there a way of checking if a persons logged in in the signup.ctp view? and redirect them from there?
Thats probably miles away from reality but I'm very confused. Any help appreciated. Cheers :)
Create an action for signup... and you can do the verification there. I don't think it's a good practice to put redirects in views. You can place the action in the Homepage controller for example...
Even if it was pretty to put the redirect in the view, you would need to set a variable (in an action) to check if user is logged in or not. :)
you can put a different link for the button in your home page..
i.e. depending on the user's status (logged in or not), you will choose which link to associate with the button..
I don't know if you're using the Auth component..
if so, in your home page's template you can do something like:
<?php
if ($session.read('Auth.User')) {
// the user is logged in
// put the link to the other action
}
else {
// the user isn't logged in
// put the link to the signup/login page
}
?>
this way, you will not need to redirect the user...
hope this helps..
good luck with your development...
Do this in your ExampleController for the specific view like "example.ctp"
public function example(){
if ($session.read('Auth.User')) {
this->redirect(['action' => 'exampleview']);
}
}
Hope that it will solve your purpose.
You can use
header ("Location: ".$this->Html->url('/'));
You can also use
header ("Location: ".$this->Html->url(array('controller'=>'Home','action'=>'index')));
for using controller and action in cakephp
I am new to Zend Frame Work.
I am using $ajaxContext = $this->_helper->getHelper('AjaxContext'); for adding action contexts. I have one Index.phtml page and all other views are ajax.phtml pages. I have to do some java script methods in the ajax.phtml pages. But i didn't find a way to refer the js files in the ajax.phtml pages. I have tried adding those in the controller init and index action, using $this->view->headScript()->appendFile, though i have the reference added in the page source, none of htese seems to be working on the ajax content. Then i tried to add it in the action for the ajax page, then it is not coming in the page source itself. As far as i understood, $this->view->headScript()->appendFile will append the file reference to the layout page and for the ajax.phtml pages, the layout will be disabled.
Is there any way that i can refer my js files in the ajax.phtml pages?
You are on the right way, but where does you echo the ViewHelper?
After adding the Files with the headScript view Helper try:
echo $this->headScript();
I found two ways to resolve this issue. One is we can bound the click event of the ajax postbacked content button with a jquery.live() method. This will register the element in the DOM, even if the element is not present at the time of page load.
Another way is to reload the javascript in the success of each ajax postback using the getScript() method. In this way all the newly added elements will get registered and active. if you are using jquery dialogs, using variables, you may have to destroy those, before reloading the js.
Put this code to your Controller public function:
public function indexController(){
$this->_helper->viewRenderer->setNoRender();
$Response = $this->getResponse();
$Response->setBody(Zend_Json::decode($foo))
->setHeader('content-type', 'application/json', true);
return null;
}