This topic is locked
[SOLVED]

 Redirect after save on popup mode

8/20/2013 12:35:54 PM
PHPRunner General questions
S
stiven author

Hello,
I'm using an add page in popup mode with the tips I found here http://xlinesoft.com...a-popup-window/ everything works fine, the only thing is that I need after record is save is it possible to besides the popup closing itself also to reload the page from where the popup was generated? here is the code I am using after save on the add page, this code closes the window but it won't reload the list page.
Thanks for your help.



$_SESSION["user_id"]=$data["id"];

echo '<script type="text/javascript" src="include/loadfirst.js"></script>

<script>

$(document).ready(functphprunnerion() {



$(".yui3-button-close", window.parent.document).trigger("click");

$(".yui3-panel-content", window.parent.document).remove();



});

</script>';



exit();
C
copper21 8/20/2013

You can try
$(".yui3-panel-content", window.location.reload(true);
My setup work like this. I added a button to a list page. When I click the button, an add page pops up. I input data and click save. When I click save, the pop up disappears and the list page from which I clicked the first button refreshes.
I am not sure how yours works, but window.location.reload(true); worked for me.
If you need me to give you details on exactly how I got my setup to work, let me know.
Brian

S
stiven author 8/20/2013

it is the same situation but it did not work for me.

C
copper21 8/20/2013

Ok,
I looked and I have another try...try this one:
opener.location.reload(true);
If this one doesn't work I will describe what I did. How are you opening up this Add Page pop-up?
Brian

S
stiven author 8/20/2013

that didn't work either. :/
I have two different methods to open this popup.
1st one is on the list page, I have add page show in pop up mode in the pages options.
When I click Add new on the list page the add page appears in pop up I need this to close and reload the page after save. here is the code I have after record added on the add page.



global $conn;
if($values['reminder'] == 'Yes'){

$sql = "INSERT INTO ies_reminders (case_no,client_name,remind_date,status,added_by,added_date) VALUES

('".$values['case_no']."','".$values['client_name']."','".$values['remind_date']."','Active',

'".$_SESSION['USER_ID_NUM']."','".date('Y-m-d H:i:s')."')";

db_exec($sql,$conn);

}
$_SESSION["user_id"]=$data["id"];

echo '<script type="text/javascript" src="include/loadfirst.js"></script>

<script>

$(document).ready(functphprunnerion() {



$(".yui3-button-close", window.parent.document).trigger("click");

$(".yui3-panel-content", window.parent.document).remove();

window.opener.location.reload(true);



});

</script>';



exit();


2nd approach is with a button on an edit page. I have a button Add New. When the user clicks the button it opens the list page in a modal popup with the same options from the same list page on the first one then the client will have the option to click add new on the popup and another popup with the add page will open, I need when the user saves the record on the add page that add page closes and the first popup refreshes

C
cgphp 8/20/2013
$_SESSION["user_id"]=$data["id"];

echo '<script type="text/javascript" src="include/loadfirst.js"></script>

<script>

$(document).ready(functphprunnerion() {



$(".yui3-button-close", window.parent.document).trigger("click");

$(".yui3-panel-content", window.parent.document).remove();



});

</script>';
header('Location: your_page_name_add.php');

exit();
C
copper21 8/20/2013

Okay, here is what I did. Much of what I did came from this post... http://www.asprunner.com/forums/topic/17019-open-javascript-popup-window-then-automatically-close-it-after-saving-it/ Thank FunkDaddy for it.
List page where you want to add record:
Create new button. I created it to the right of the standard PHP Runner buttons (Add new, Edit selected...) and not in the row data.
Button Properties:
Name your button
Clear Server and Client After Tabs
In Client Before, add this:
window.open('http://SERVERNAME/APPLICATIONNAME/ADDPAGE_add.php','popUpWindow','height=775,width=825,left=20,top=20,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes';)
You can change the window size and resize/toolbar options as needed.
Add Page that is being opened:
Go to the add page in the editor that you are opening up in a pop-up. (The same as the one you put in the URL above "Client Before" tab.)
Go to HTML mode and add new "Save" Button where you want it. I put it to the left of the existing save button:
<SPAN class=runner-btnframe><SPAN class=runner-btnleft></SPAN><SPAN class=runner-btnright></SPAN><A id=save_record class=runner-button href="#">SAVE RECORD</A> </SPAN>
Go to the event editor of that add page that you are popping-up:
Add the following JS to JavaScript OnLoad Event of that add page:
//Save and close
$("#save_record").bind("click", {page: this}, function(e){

var page = e.data.page;

page.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

formObj.baseParams['save_record'] = 'SAVE RECORD';

}, page, {single: true});

page.on('afterSave', function(respObj, formObj, fieldControlsArr, pageObj){

delete formObj.baseParams['save_record'];

window.opener.location.reload(true);

}, page, {single: true});

page.saveHn(e);

});
Add the following code to the After Record added of that add page:
//Refresh List page
if ($_REQUEST["save_record"]=="SAVE RECORD")

{

echo "<script>opener.location.reload(true);</script>";
}
//Save and close form
if ($_REQUEST["save_record"]=="SAVE RECORD")

{

echo "<script type=\"text/javascript\">window.close();</script>";

exit();

}
Add the following code to Before Display of the add page that you are popping up:
//Disable buttons

$xt->assign("backToMenu_button", false);

$xt->assign("save_button", false);

$xt->assign("cancel_button", false);

$xt->assign("back_button", false);
I hope this helps,
Brian

C
cgphp 8/20/2013

Because you want to redirect after the record has been added, you can send a raw HTTP header:

$_SESSION["user_id"]=$data["id"];

echo '<script type="text/javascript" src="include/loadfirst.js"></script>

<script>

$(document).ready(functphprunnerion() {



$(".yui3-button-close", window.parent.document).trigger("click");

$(".yui3-panel-content", window.parent.document).remove();



});

</script>';
header('Location: your_page_name_add.php');

exit();
S
stiven author 8/20/2013

Thanks for the update, but it isn't working the modal popup closes but it won't redirect or reload the previous page. here is the code.



$_SESSION["user_id"]=$data["id"];

echo '<script type="text/javascript" src="include/loadfirst.js"></script>

<script>

$(document).ready(function() {



$(".yui3-button-close", window.parent.document).trigger("click");

$(".yui3-panel-content", window.parent.document).remove();


});

</script>';

header("Location: ies_case_log_list.php?cid=".$values['case_no']."");

exit();




Because you want to redirect after the record has been added, you can send a raw HTTP header:

$_SESSION["user_id"]=$data["id"];

echo '<script type="text/javascript" src="include/loadfirst.js"></script>

<script>

$(document).ready(functphprunnerion() {
$(".yui3-button-close", window.parent.document).trigger("click");

$(".yui3-panel-content", window.parent.document).remove();
});

</script>';
header('Location: your_page_name_add.php');

exit();


C
cgphp 8/20/2013

Sorry Stivens, I was not considering it is an AJAX call. Please, post the code of the script of your modal popup dialog.

S
stiven author 8/20/2013

no problem <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=71820&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> thanks for your help
the modal popup is the default page phprunner generates when I select show in popup the add page. when the window closes the record would normally appear on the list page. But in this case I have filtered the results on the list page passing a value through the url ies_case_log.php?cid=$id. That's why I need the list page to reload so that I can see the record that was just added.
In the other case. I followed the example from the website that is posted in tips and tricks here is my code.



function displayPopup(params)

{

var pageid=1;

var pageObj = Runner.pages.PageManager.getById(pageid);

args = {

bodyContent: "<iframe frameborder='0' id='popupIframe" + pageid + "' style='width: 100%; height: 100%; border: 0;'></iframe>",

footerContent: "<span>&nbsp;</span>",

headerContent: params.headerContent,

centered: true,

render: true,

width: params.width ? params.width : 800,

height: params.height ? params.height : 600

},

afterCreateHandler = function(win) {

var bodyNode = $(win.bodyNode.getDOMNode()),

iframeNode = $("iframe#popupIframe" + pageid, bodyNode);



iframeNode.load(function() {

if (Runner.isChrome) {

bodyNode.addClass("noScrollBar");

}

win.show();



}).attr("src", params.url);

},

afterCloseHandler = params.afterClose;



if (Runner.isChrome) {

$("< style type='text/css'> .yui3-widget-bd::-webkit-scrollbar {display:none;} < /style>").appendTo("head");

}



Runner.pages.PageManager.createFlyWin.call(pageObj, args, true,

afterCreateHandler, afterCloseHandler);

}



function AddLog(id)

{



params = {

url: 'ies_case_log_list.php?cid='+id,

afterClose: function(win) {

win.destroy(true);

},

headerContent: 'Add Log'

};

displayPopup(params);

}

C
cgphp 8/20/2013

Update the AddLog function as follow:

function AddLog(id)

{



params = {

url: 'ies_case_log_list.php?cid='+id,

afterClose: function(win) {

win.destroy(true);

location.href = 'ies_case_log_list.php';

},

headerContent: 'Add Log'

};

displayPopup(params);

}


Replace the value of the location.href with the page where you want to redirect the user to.

S
stiven author 8/21/2013

Thanks Christian this works great this is how the function ended up.
I only have one little problem. in my first case when I call the function on the list page after save it redirects correctly, on the second case I call the function from an edit page. and I am calling to open the list page first in a popup, then in the popup i can open the add page in another popup so I end up with two modal popup windows. after save the second popup closes and the first popup reloads which is just what I need but then when I close the first popup the edit page reloads to the list page which I don't want this to happen, do you think there is any way to fix this?
THanks.



function AddLog(url,id,w,h)

{
params = {

url: url,

width: w,

height: h,

afterClose: function(win) {

win.destroy(true);

location.href = 'ies_case_log_list.php?cid='+id;

},

headerContent: 'Add Log'

};

displayPopup(params);

}




Update the AddLog function as follow:

function AddLog(id)

{
params = {

url: 'ies_case_log_list.php?cid='+id,

afterClose: function(win) {

win.destroy(true);

location.href = 'ies_case_log_list.php';

},

headerContent: 'Add Log'

};

displayPopup(params);

}


Replace the value of the location.href with the page where you want to redirect the user to.

C
cgphp 8/21/2013

Are you using a different function for the second case?

S
stiven author 8/21/2013

No, I am using the same function for both cases I can show you how I call them in both cases.


//first case from the list page.

$link = '<A class=runner-button href="#" onclick="AddLog(\'ies_case_log_add.php?cid='.$_GET['cid'].'\',\''.$_GET['cid'].'\',\'560\',\'400\')">Add New</A>';g
//second case from the edit page
<A onclick="AddLog('ies_case_log_list.php?cid={$show_key1}','{$show_key1}','800','600')" class=runner-button href="#">Add New</A>




Are you using a different function for the second case?

C
cgphp 8/21/2013

You can add a parameter for the redirection url as follows:

function AddLog(url,id,w,h,url_redirection)

{
params = {

url: url,

width: w,

height: h,

afterClose: function(win) {

win.destroy(true);

location.href = url_redirection;

},

headerContent: 'Add Log'

};

displayPopup(params);

}


You will set the url_redirection to the list page or to the edit page.

S
stiven author 8/21/2013

Thanks Cristian,
The redirection url is good how it is right now, what I would like to do is to stop the redirection when I close the first popup that was open, I hope this makes sense.
Whats happening right now is that the first popup opens then when I click add new on the popup a second popup opens up, which is the add page, after I save the record the second popup closes and the first one reloads which is good. the problem is when I want to close the first modal popup the edit page reloads and redirects to another page. but I would like the edit page to not reload or redirect.



You can add a parameter for the redirection url as follows:

function AddLog(url,id,w,h,url_redirection)

{
params = {

url: url,

width: w,

height: h,

afterClose: function(win) {

win.destroy(true);

location.href = url_redirection;

},

headerContent: 'Add Log'

};

displayPopup(params);

}


You will set the url_redirection to the list page or to the edit page.

C
cgphp 8/21/2013
function AddLog(url,id,w,h,url_redirection)

{
params = {

url: url,

width: w,

height: h,

afterClose: function(win) {

win.destroy(true);

if(url_redirection !== '')

{

location.href = url_redirection+id;

}

},

headerContent: 'Add Log'

};

displayPopup(params);

}


In the first case you call the AddLog function as follows:

AddLog(\'ies_case_log_add.php?cid='.$_GET['cid'].'\',\''.$_GET['cid'].'\',\'560\',\'400\',\'ies_case_log_list.php?cid=\')


In the second case you call the AddLog function as follows:

AddLog('ies_case_log_list.php?cid={$show_key1}','{$show_key1}','800','600','')
S
stiven author 8/21/2013

This is great!!! Thank you so much for your help this worked!!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=71838&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />


function AddLog(url,id,w,h,url_redirection)

{
params = {

url: url,

width: w,

height: h,

afterClose: function(win) {

win.destroy(true);

if(url_redirection !== '')

{

location.href = url_redirection+id;

}

},

headerContent: 'Add Log'

};

displayPopup(params);

}


In the first case you call the AddLog function as follows:

AddLog(\'ies_case_log_add.php?cid='.$_GET['cid'].'\',\''.$_GET['cid'].'\',\'560\',\'400\',\'ies_case_log_list.php?cid=\')


In the second case you call the AddLog function as follows:

AddLog('ies_case_log_list.php?cid={$show_key1}','{$show_key1}','800','600','')