No content on wordpress dashboard page after form submit - php

I'm building a plugin, but somehow when I post a form and redirect back to the page, the page is empty. Content returns after a page reload.
I use the following after the (successful) form submit.
wp_redirect(get_permalink());
exit();
I don't seem to get any errors (I do have WP_DEBUG on).

There can be cache in your browser or web server. You can try generate unique link for reload. For example add to url parameter.
$url = add_query_arg("unique", time(), get_permalink());
wp_redirect($url);
exit();

Related

PHP page redirect adding target page to bottom of current page

I've got a registration page and a landing page, when the register button is pressed it activates a JS function in an external JS file (reg.js) that then runs reg.php, like so:
reg.html->reg.js->reg.php
If the registration succeeds it is supposed to redirect to a landing page (landing.php) but instead it is just appending the landing page to the bottom of the current page(reg.html), like so:
Register
[register button]
Landing
[landing page text]
The redirection code is:
header('Location: landing.php');
From the sounds of it, you're posting via AJAX to a php script to process. PHP would then need to send some sort of success response back to the AJAX—something like:
if (registered) {
header(201); // http response code for "created"
}
The AJAX callback would see that success, and then you would redirect the user client-side:
$.post().success(function() { window.location = '/landing.php'; });
Are you using javascript ajax ? If yes then you need to use
window.location = 'http://webiste.com';
If your javascript submits the form then you need to use header in PHP code like this:
header( 'Location: http://website.com/landing.php' ) ;
Don't forget to add http:// in the redirect url as this may be causing an issue.
<?php
if(registered)
{
header( 'Location: /landing.php' ) ;
}
?>
or try to input the whole url.

Redirect Lightbox after form submission

I'm using Fancybox 2 to display some forms on my website. The form comes through from an external page into an IFrame to let the user post a message, kind of like twitter does. However I want the user to be re-directed after the form has been posted. So they post the form to a database, the Fancybox window shuts down and then they are redirected to the posts page where they see their newly posted message. Is there a way of doing this succesfully?
You can try this:
<script>
if(data == 1){
//window.location.replace("dashboard.php"); //will open the page in the fancybox
parent.$.fancybox.close(); //will close the fancybox
//parent.window.location.replace( your_url_here ); //your redirecting URL here
parent.window.location.href = 'dashboard.php'; //your redirecting URL here
}
</script>
I would recommend you to use a real form rather than a post action. You are not really using form submission otherwise, but just a POST request.
If you do that, you could use the target="_top" inside the <form tag and submit the results using the submit function of jQuery.

Javascript location reload without get perimeter

How can I make "location.reload()" on php file without get perimeter ?
Here is an example..
Let's say I have PHP, and at the right top, I have logout button.
When user press that button, PHP will automatically re-direct to "index.php?logout" and after that, i will logout (unset cookie and other) and return ( javascript location.reload() ) to main page (login page)
Problem that I have is, when php return to login page after logout, then url is still "index.php?logout", so when user login back with "index.php?logout" page, it will automatically logout (because of ?logout perimeter on url)..
So how can I tackle this problem ? Anybody got any idea ?
I hope you all understand what i'm trying to tell you all about..
Thanks for reading this..
use self.location.reload instead of location.reload. Because location.reload reloads the current page. You can simple use
self.location.reload = index.php
Or you can remove query paramter from your url like
var url = 'index.php?logout'
url=url.split("?")[0];
location.reload =url
location.reload() reloads the current page with the post data,you should use window.location.href in case of login/logout
When user press that button, PHP will automatically re-direct to "index.php?logout" and >after that, i will logout (unset cookie and other) and return ( javascript location.reload() >) to main page (login page)
all these can be implemented in server side.
// LOGOUT
if(isset($_GET['logout'])){
//logout code
}
header('location: www.yoursite.com/login') //or whatever the url is
exit;
you re-direct to login page and save page url that request for login that is index.php?logout for re-direct back you must check perimeter logout if exist remove it from return url for example
//replace parent::$Patch with your root url like "http://localhost/myapp/"
if(!parent::$Patch.'admin/login.php'=='http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']){//check if you are in login.php page didn't redirect to login.php
if(!#header('Location:'.parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])))){
//if header error echo javaScript code for re-direct
?>
<!DOCTYPE HTML>
<html>
<head>
<script language="javascript">
var LoadP = <?php print "'".parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))."'"?>;
self.location = LoadP;
</script></head></html>
<?php
}
exit();
}
}
this code re-direct user to login page and keep return url of page. if logout exist inside of return url remove it
i hope it can help you

PHP header redirect in jQuery Mobile

I'm working on a jquery mobile web app and do a sessioncheck with php on pages I need the user to be logged-in. If not, the user will be redirected to the login.php?r=L29yZGVyLnBocD9kZWFsX2lkPTEwMDM2MjM= (base64_encode($_SERVER['REQUEST_URI']) to login. After the login he has to be redirected to the page he actually requested.
Unfortunately JQM doesn't update the URL, so i can't grab the GET parameter ?r=.... as it is not there. Just a page reload (F5) updates the url.
Here the sessioncheck code which does the redirect if user is not logged-in:
if(!isset($_SESSION["member"]) || (isset($_SESSION["member"]) && (int)$_SESSION["member"]["member_id"]==0)){
unset($_SESSION["member"]);
Header("Location: " . SITE_ROOT . "/login.php?r=".base64_encode($_SERVER['REQUEST_URI']));
exit;
}
What do you guys suggest to tell jQuery mobile that the target has changed.
Of course my redirect happens before the DOCTYPE tag
Cheers
Did you specify a data-url attribute into the page div?
<div data-role="page" data-url="/login" id="login-page">

Javascript alert in php script

I wanted to popup an alert box. After that, the site would redirect to main page. But, it seems that it directly redirect to the mainpage without alerting anything.
if($registerquery)
{
?>
<script>alert('received!')</script>
<?php
}
header("Location: mainpage.php");
exit();
?>
I wanted to do this to ensure users that the process of submission ended successfully. How can i alert something before the page redirect to mainpage and more importantly what causes this? I think the page should not have redirected before the alert box.(Before these codes, site registers what users submitted but not relevant i guess.)Thanks
You just can't do this. PHP is server-side, JS is client-side. Using a location header is server-side, so the browser never gets the JS.
Instead, try something more like:
if( $registerquery)
echo "<script>alert('received!'); location.href='mainpage.php';</script>";
and remove the header bit altogether.

Categories