This topic is locked
[SOLVED]

 Made a new button (save and process other things)

1/31/2014 4:23:39 PM
PHPRunner General questions
N
notuo author

Hi. I made a new button in an edit page to process the form, save the changes and process other things.
Is working kind of OK but never enter the "Client After" event. Any idea is appreciate.
This is the Code:

CLIENT BEFORE:

params["txt"] = "";
pageObj.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

formObj.baseParams['golist'] = "1";

});

$("#saveButton1").click();

return false;


Server

global $conn;

define(NL, "\n");

$result["error"] = "";
$data = $button->getCurrentRecord();
if ($data["ya_pdf"] != 1) $result["error"] .= "Error, falta PDF" . NL;

...

if ($data["ya_domicilio"] != 1) $result["error"] .= "Error, falta comprobante de domicilio" . NL;
echo ($result["error"] . NL);
if ($result["error"] == "") {

echo "no hay error " . $result["error"] . NL;

$sql = "INSERT INTO studentyear values('" . $data["alumnosID"] . "', '" . date("Y") . "')";

$rs = db_query($sql, $conn);

$result["txt"] = "Alumno registrado en el programa del año: " . date("Y");

}
echo "terminando " . $result["error"] . NL;


I can catch all the "echo"'s that apply in firebug
Client after

var errormsg = result["error"];

var message = result["txt"];
alert("después");

alert(errormsg);

alert(message);
if (result["error"] != "") {

alert(result["error"])

} else {



ctrl.setMessage(message);

}


Thanks in advance,

N
notuo author 2/1/2014

Well.
I found that the Save button or this copy of the save button is not exactly like the buttons we use with insert button. The Save button behaves different.
So the solution is to pass the button's Server and Client after code to the "After record saved" with the proper changes of syntax for the javascript and variable names.
In my case, I had to add some specific code like

echo "<script type=\"text/javascript\">alert('Aviso:\\n'+" . $msg . ");location.href='documentosalumnos_list.php';</script>";



mainly because the original event/page is no longer available.