Ask Confirm when change page

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Fakiro82
User
Posts: 108

Ask Confirm when change page

Post by Fakiro82 »

Hi,
I need to ask confirm when user modify record but not click on submit.
Now, when user modify record without clik on submit and then change page, the page is changed but the changes to the record are lost.
How can i do to ask a confirm when user change page?

Thank you all,
Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Google "beforeunload jquery". You may simply put that jQuery code in "Startup Script" section.

Please read "Server Events and Client Scripts" topic for more information.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

I tried with your advice and it work ;)
Is it possible use beforeunload with CKEditor?
I searched in internet but I could not figure out how to do it.
Do you know I can i do?

Thank you so much,
Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

This should be working, as I've just tried it:

function beforeUnload(evt) {
for (var name in CKEDITOR.instances) {
if (CKEDITOR.instances[name].checkDirty())
return evt.returnValue = "messageUnsaved";
}
}

if (window.addEventListener)
window.addEventListener('beforeunload', beforeUnload, false);
else
window.attachEvent('onbeforeunload', beforeUnload);


Fakiro82
User
Posts: 108

Post by Fakiro82 »

  1. I need to Insert in table attachment information file after upload like (filenem,extension and full path). I have read that I must use the pathinfo function but I don't know how can i do this.
  2. I need to insert in table a new record with some information get from another table. Example:

Table 1
field 1, field 2, field 3, field 4 (select list). When I change the select in table 1 I need to insert new record in table 2 with some information from table 1. I create this script:

In the select field in "Client side events" I insert this code:

{ // keys = event types, values = handler functions
"change": function(e) {
// Your code
var $row = $(this).fields();
//get selected value
var IntIDSituazione = $row["int_IDSituazione"].value();
console.log(filed_value);
//post to php code to perform an action
$.post(ew_CurrentPage(), { "myajax": 1, "token": EW_TOKEN, "int_IDSituazione": IntIDSituazione }, function(result) { // Post back your custom data (with the synchronizer token)
//do soemthing after it has finished
console.log(result);
});

}

}

In the "Code (Server events, Client Script and Custom Template)" section in Server Events --> Table-Specific-->Edit Page--> Page_Load I insert this code:

// Page Load event
function Page_Load() {

if (@$POST["myajax"] == 1 && @$POST["int_IDSituazione"] != "" ) { // Check if it is your custom Ajax and if the query value is present
//do your insert now
$return_value = ew_Execute("INSERT INTO tbl_note( CodiceDocumento, int_RiferimentoNota) VALUES( '" . $rsnew["CodiceDocumento"] . "', '" . $rsnew["int_IDSituazione"] ."'");
// Get the desired value (assume ProductID is integer so no need to quote the value)
if($return_value == null)
{echo "Errore durante l'inserimento in Storico Note";}
else
{echo "La nota in storico note è stata inserita con successo";}
$this->Page_Terminate(); // Terminate the page such that this return is all that matters
}
//echo "Page Load";
}

But not worked.

Ho can i do this?

Thank you so much for your help.
Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Always double check your code, especially this one:

$return_value = ew_Execute("INSERT INTO tbl_note( CodiceDocumento, int_RiferimentoNota) VALUES( '" . $rsnew["CodiceDocumento"] . "', '" . $rsnew["int_IDSituazione"] ."'");

There is no $rsnew object that you can use in "Page_Load" server event. So, that SQL will always failed.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Thank you so much.
And so, What can I write in code to insert correct value? Can I insert code always in Page_Load server event or need change this?
And, for the information file upload? What can I do?

Sorry for this answer but i'm new phpmaker user.

Many thanks for your help.

Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

  1. What is the type of "CodiceDocumento" field? Is it a auto increment field? If so, then you don't need to include it in that SQL.
  2. Change $rsnew["int_IDSituazione"] to $_POST["int_IDSituazione"] in your SQL.

Fakiro82
User
Posts: 108

Post by Fakiro82 »

"CodiceDocumento" is not a autoincrement ID. The Autoincrement ID is "Progressivo".
I tried to modify the code in page editpage-->page_load with your suggestion:

// Page Load event
function Page_Load() {

if (@$POST["myajax"] == 1 && @$POST["int_IDSituazione"] != "" ) { // Check if it is your custom Ajax and if the query value is present
//do your insert now
$return_value = ew_Execute("INSERT INTO tbl_note( CodiceDocumento, int_RiferimentoNota) VALUES( '" . $POST["CodiceDocumento"] . "', '" . $POST["int_IDSituazione"] ."'");
// Get the desired value (assume ProductID is integer so no need to quote the value)
if($return_value == null)
{echo "Errore durante l'inserimento in Storico Note";}
else
{echo "La nota in storico note è stata inserita con successo";}
$this->Page_Terminate(); // Terminate the page such that this return is all that matters
}
//echo "Page Load";
}

but not work. Where am I wrong? How can I do it to make it work?

Many thanks,
Andrea


mobhar
User
Posts: 11660

Post by mobhar »

When you included "CodiceDocumento" as a post variable in Page_Load server event, then make sure also you have already included that varibale from jQuery post in the "change" client event.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

I understand why it does not add the record. Because table2 is linked to table1 as the master / detail table.
Could it be that is why it does not work? Do I need to change my code? Does the onchange event also work on master / detail tables?

Thank you so much,
Andrea


mobhar
User
Posts: 11660

Post by mobhar »

Fakiro82 wrote:
Does the onchange event also work on master / detail tables?

It should work properly also, as long as you write the right code that expose the values from the related elements on the form.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi mobhar,
now it's working but only if I use fixed text in VALUES like below:

// Page Load event

function Page_Load() {

if (@$POST["myajax"] == 1 && @$POST["int_IDSituazione"] != "" ) { // Check if it is your custom Ajax and if the query value is present
//do your insert now
$return_value = ew_Execute("Insert into tbl_storiconote(CodiceDocumento,des_Nota,des_TipologiaNota,int_NumeroModifiche) VALUES ('123456789012', 'Nota di Test', 'S',1)"); // Get the desired value (assume ProductID is integer so no need to quote the value)
if($return_value == null)
{echo "Errore durante l'inserimento in Storico Note";}
else
{echo "La nota in storico note è stata inserita con successo";}
$this->Page_Terminate(); // Terminate the page such that this return is all that matters
}
//echo "Page Load";
}


If I try to pass value from table1 to table2 using VALUES ('".$_POST['CodiceDocumento']."') not work.
How can I do this? How can I pass value from table1 to table2 in VALUES? Is correct my code below?

// Page Load event

function Page_Load() {

if (@$POST["myajax"] == 1 && @$POST["int_IDSituazione"] != "" ) { // Check if it is your custom Ajax and if the query value is present
//do your insert now
$return_value = ew_Execute("Insert into tbl_storiconote(CodiceDocumento,des_Nota,des_TipologiaNota,int_NumeroModifiche) VALUES ('".$POST['CodiceDocumento']."', '".$POST['des_Nota']."', 'S',1)"); // Get the desired value (assume ProductID is integer so no need to quote the value)
if($return_value == null)
{echo "Errore durante l'inserimento in Storico Note";}
else
{echo "La nota in storico note è stata inserita con successo";}
$this->Page_Terminate(); // Terminate the page such that this return is all that matters
}
//echo "Page Load";
}

Thank you so much mobhar for your help.
Andrea


mobhar
User
Posts: 11660

Post by mobhar »

Always post your latest code in "change" client event for more discussion.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi mobhar,
this code for change client event:

{ // keys = event types, values = handler functions
"change": function(e) {
// Your code
var $row = $(this).fields();
//get selected value
var IntIDSituazione = $row["int_IDSituazione"].value();
console.log(IntIDSituazione);
//post to php code to perform an action
$.post(ew_CurrentPage(), { "myajax": 1, "token": EW_TOKEN, "int_IDSituazione": IntIDSituazione }, function(result) { // Post back your custom data (with the synchronizer token)
//do soemthing after it has finished
console.log(result);
});

}

}

This code is for Page_Load (in Specific-Table):

// Page Load event

function Page_Load() {

if (@$POST["myajax"] == 1 && @$POST["int_IDSituazione"] != "" ) { // Check if it is your custom Ajax and if the query value is present
//do your insert now
$return_value = ew_Execute("Insert into tbl_storiconote(CodiceDocumento,des_Nota,des_TipologiaNota,int_NumeroModifiche) VALUES ('".$POST['CodiceDocumento']."', '".$POST['des_Nota']."', 'S',1)"); // Get the desired value (assume ProductID is integer so no need to quote the value)
if($return_value == null)
{echo "Errore durante l'inserimento in Storico Note";}
else
{echo "La nota in storico note è stata inserita con successo";}
$this->Page_Terminate(); // Terminate the page such that this return is all that matters
}
//echo "Page Load";
}

If I use '".$POST['CodiceDocumento']."' or others value with $POST, the record is added but the values ​​I want to pass with the $ _POST are blank.

Thank you so much mobhar.

Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

When you included "des_Nota" as a post variable in Page_Load server event, then make sure also you have already included that varibale from jQuery post in the "change" client event.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Thank you so much mobhar,
now it's work.

Thank you,
Andrea.


Post Reply