Page 1 of 1

Ask Confirm when change page

Posted: Thu Nov 02, 2017 6:40 pm
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.


Re: Ask Confirm when change page

Posted: Thu Nov 02, 2017 6:45 pm
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.


Re: Ask Confirm when change page

Posted: Mon Nov 06, 2017 5:07 pm
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.


Re: Ask Confirm when change page

Posted: Mon Nov 06, 2017 6:48 pm
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);


Re: Ask Confirm when change page

Posted: Tue Nov 07, 2017 7:05 pm
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.


Re: Ask Confirm when change page

Posted: Tue Nov 07, 2017 10:07 pm
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.


Re: Ask Confirm when change page

Posted: Wed Nov 08, 2017 7:40 am
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.


Re: Ask Confirm when change page

Posted: Wed Nov 08, 2017 11:05 am
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.

Re: Ask Confirm when change page

Posted: Fri Nov 10, 2017 7:21 am
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


Re: Ask Confirm when change page

Posted: Fri Nov 10, 2017 10:32 am
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.


Re: Ask Confirm when change page

Posted: Mon Nov 13, 2017 12:57 am
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


Re: Ask Confirm when change page

Posted: Mon Nov 13, 2017 10:08 am
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.


Re: Ask Confirm when change page

Posted: Thu Nov 16, 2017 10:19 pm
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


Re: Ask Confirm when change page

Posted: Fri Nov 17, 2017 10:22 am
by mobhar

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


Re: Ask Confirm when change page

Posted: Fri Nov 17, 2017 4:53 pm
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.


Re: Ask Confirm when change page

Posted: Sat Nov 18, 2017 12:11 am
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.


Re: Ask Confirm when change page

Posted: Mon Nov 20, 2017 7:45 pm
by Fakiro82

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

Thank you,
Andrea.