Skip to content

Commit 1162e1e

Browse files
committed
updating functionality to ensure onAdd callback functions can be called before script execution - to ensure cookies can be set.
1 parent 1e05b46 commit 1162e1e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

ajaxCRUD.class.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* Basic users should NOT need to ever edit this file */
33

44
/************************************************************************/
5-
/* ajaxCRUD.class.php v8.71 */
5+
/* ajaxCRUD.class.php v8.72 */
66
/* =========================== */
77
/* Copyright (c) 2013 by Loud Canvas Media (arts@loudcanvas.com) */
88
/* http://www.ajaxcrud.com by http://www.loudcanvas.com */
@@ -281,7 +281,8 @@ class ajaxCRUD{
281281
changed by setting them via $obj->addText = "Añadir"
282282
*/
283283
var $emptyTableMessage;
284-
var $addText, $deleteText, $cancelText;
284+
var $addText, $deleteText, $cancelText; //text values for buttons
285+
var $addMessage; //used when onAddExecuteCallBackFunction is leveraged
285286

286287
var $sort_direction; //used when sorting the table via ajax
287288

@@ -362,6 +363,7 @@ function ajaxCRUD($item, $db_table, $db_table_pk, $ajaxcrud_root = "") {
362363
$this->deleteText = "Delete";
363364
$this->cancelText = "Cancel";
364365
$this->emptyTableMessage = "No data in this table. Click add button below.";
366+
$this->addMessage = ""; //when blank, defaults to generic '{Item} added' message
365367

366368
$this->onAddExecuteCallBackFunction = '';
367369
$this->onFileUploadExecuteCallBackFunction = '';
@@ -962,7 +964,12 @@ function doAction($action){
962964
$insert_id = mysql_insert_id(); //the old, mysql way of getting it (procedurual php)
963965
}
964966

965-
$report_msg[] = "$item Added";
967+
if ($this->addMessage == ""){
968+
$report_msg[] = "$item Added";
969+
}
970+
else{
971+
$report_msg[] = $this->addMessage;
972+
}
966973

967974
if ($uploads_on){
968975
foreach($this->file_uploads as $field_name){
@@ -975,7 +982,7 @@ function doAction($action){
975982
}
976983

977984
if ($this->onAddExecuteCallBackFunction != ''){
978-
$submitted_array[id] = $insert_id;
985+
$submitted_array['id'] = $insert_id;
979986
$submitted_array[$this->db_table_pk] = $insert_id;
980987
call_user_func($this->onAddExecuteCallBackFunction, $submitted_array);
981988
}
@@ -1823,7 +1830,13 @@ function showTable(){
18231830
//$add_html .= " <input type=\"button\" value=\"Go Back\" class=\"btn\" onClick=\"history.back();\">\n";
18241831
$add_html .= "</center>\n";
18251832

1826-
$add_html .= "<form action=\"" . $_SERVER['PHP_SELF'] ."#ajaxCRUD\" id=\"add_form_$this->db_table\" method=\"POST\" ENCTYPE=\"multipart/form-data\" style=\"display:none;\">\n";
1833+
$formActionURL = $_SERVER['PHP_SELF'];
1834+
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != ""){
1835+
//some web applications require posting to the same exact page (with parameters included); this is useful if/when onAddExecuteCallbackFunction is used
1836+
$formActionURL = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
1837+
}
1838+
1839+
$add_html .= "<form action=\"" . $formActionURL . "#ajaxCRUD\" id=\"add_form_$this->db_table\" method=\"POST\" ENCTYPE=\"multipart/form-data\" style=\"display:none;\">\n";
18271840
//$add_html .= "<br /><h3 align='center'>New <b>$item</b></h3>\n";
18281841
$add_html .= "<br />\n";
18291842
$add_html .= "<table align='center' name='form'>\n";

css/default.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ input, select, textarea{
8282
.btn{
8383
font-size: 11px;
8484
}
85-
.report {
85+
.report, .alertgood {
8686
text-align: left;
8787
border-top: 1px solid #9c9;
8888
border-bottom: 1px solid #9c9;
@@ -93,7 +93,7 @@ input, select, textarea{
9393
background: url("checkicon.gif") #e2f9e3 left no-repeat;
9494
}
9595

96-
.error {
96+
.error, .alertbad {
9797
text-align: left;
9898
font-weight: bold;
9999
border-top: 1px solid #c99;

0 commit comments

Comments
 (0)