Though I can be dangerous with my PHP, when it comes to JavaScript, I am far from competent.
The tools have several examples of a button in DV and TV to execute some JavaScript, but the examples just get values...
The problem I've trying to solve (and not very successfully) is my users want, in the table view, to hit a button and "close" the record, ie: set and save the "closed_date" field with today's date w/o opening the record, and refresh the TV to see new status.
If that is not possible, once the record in opened in DV, hit an action button and again, set and save the "closed_date" field and go back to TV.
Any examples or guidance would be appreciated.
Thanks!.
Set/Save field value via Button
Re: Set/Save field value via Button
Hi,
see my footer, how to insert a new button (2nd save button). You can also use AppGini Helper (viewforum.php?f=13).
The button should have a SUBMIT type and you can simpy add a to it. Once the form has been submitted, check in the hooks/tablename.php -> _init function, if the GET parameter "setDate" is set and if so, see if it has the value 1. If the setDate is equal to 1, then write some php code (in the before_update function) to add the current date to a field.
If the field is read-only or hidden, the variable $data['yourFieldname'] is not available. In this case you can write the date in the after_insert (and after_udpate) function.
Well, no code, just guidance
Olaf
see my footer, how to insert a new button (2nd save button). You can also use AppGini Helper (viewforum.php?f=13).
The button should have a SUBMIT type and you can simpy add a
Code: Select all
?setDate=1
If the field is read-only or hidden, the variable $data['yourFieldname'] is not available. In this case you can write the date in the after_insert (and after_udpate) function.
Well, no code, just guidance
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Set/Save field value via Button
Thank you! Definitely gives me something to work with... !
Re: Set/Save field value via Button
Hi,
if I understood your question right, it was about adding a button to table view and, on click (clientside), changing a database value on serverside using PHP. Here is how you can do using AppGiniHelper Javascript Library functions. I have inserted many comments for better understanding for beginners.
You are familiar with PHP, so I'm not showing the complete PHP code for the second part (serverside part) but just naming the relevant steps for server side.
Part 1: Javascript (clientside)
On mouseover check the URL of each button. The placeholder %ID% has been replaced by the primary key per row.
Part 2: PHP (serverside)
if I understood your question right, it was about adding a button to table view and, on click (clientside), changing a database value on serverside using PHP. Here is how you can do using AppGiniHelper Javascript Library functions. I have inserted many comments for better understanding for beginners.
You are familiar with PHP, so I'm not showing the complete PHP code for the second part (serverside part) but just naming the relevant steps for server side.
Part 1: Javascript (clientside)
Code: Select all
// file: hooks/TABLENAME-tv.js
// change the PHP filename
// you can use placeholder %ID% in your url
var url = "tasks_close.php?SelectedID=%ID%";
// wait for document ready due to lazy loading of table
jQuery(document).ready(function () {
var tv = AppGiniHelper.tv;
// we need some space for the button.
// Change width of first column to 150px
tv.setWidth(0, 150);
// add a button to TV table on EVERY row
tv.addLink(url, "ok", "Close Record");
// 2nd parameter: glyphicon name
// 3rd parameter: button text
});
On mouseover check the URL of each button. The placeholder %ID% has been replaced by the primary key per row.
Part 2: PHP (serverside)
Code: Select all
<?php
// file: tasks_close.php
include("language.php");
include("lib.php");
// get SelectedID parameter from $_REQUEST
// check edit-permissions for that specific record and current user
// do your database changes using sql("YOUR SQL COMMAND", $eo);
// redirect to table view or detail view using PHP redirect("..."); function
// error handling
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Set/Save field value via Button
Perfect!
I was already doing something similar with an external function, didn't make the connection to do the same thing to update the record...
Thank you again for making me think about this correctly.
I was already doing something similar with an external function, didn't make the connection to do the same thing to update the record...
Thank you again for making me think about this correctly.