Step 1.
Add the following code via a "insert php snippet" to the page where you want to include a link (or button if you choose) to open a new popup window.
echo "
<!-- Codes by Quackit.com -->
<script type=\"text/javascript\">
// Popup window code
function newPopup(url) {
        popupWindow = window.open(
                url,'popUpWindow','height=400,width=530,left=20,top=20,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>
<a href=\"Javascript:newPopup('http://localhost/your_other_application_form_add.php');\">Add New Comment</a>"
;


Step 2.
In the page that gets opened inside the popup window, you add this code to Javascript onload
$("#submit2").bind("click", {page: this}, function(e){
var page = e.data.page;
page
.on('beforeSave', function(formObj, fieldControlsArr, pageObj){
formObj
.baseParams['submit2'] = 'Save and back to list'; }, page, {single: true});
page
.on('afterSave', function(respObj, formObj, fieldControlsArr, pageObj){ delete formObj.baseParams['submit2'];
}, page, {single: true});
page
.saveHn(e);
});


Step 3.
Add a new button (or simply replace existing save button) on that popup form to "save and close" such as:
<INPUT class=button id=submit2 type=button value="Save And Close" name=submit2>


Step 4.
Now, in the same popup form go to the event "After Record Added" (or if editing find the event counterpart) and add this:
if ($_REQUEST["submit2"]=="Save And Close")
{
echo
"<script type=\"text/javascript\">window.close();</script>";
exit();
}


That is it. Now your popup will automatically save and close. 



Cheers, 


Tried doing this on new PHPR project (version 6.2 build 15275) and it appears that you can now simply add something like this to the "after record added" event to close the page after it is saved:
//Close window after save
echo
"
<script type=\"text/javascript\">
        alert('Congratulations - your entry was saved');
        window.close();
</script>"
;


Much simpler. I'm not sure why this wasn't working in earlier versions. Bottom line is that now you can forget everything I mentioned in this previous post if using a newer version of PHPR. No need to add custom button or javascript :-) 


Slight improvement (works from PHPR 5.3 and UP)
//Save popup and refresh window!
echo
"
<script type=\"text/javascript\">
                        window.parent.location.reload(true);
                  self.close();
</script>"
;

Post a Comment