• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Fabrik Form custom PHP - Update 2 fields if condition is met

Tessa

Member
Hi!

I have a List that I need to add a functionality to update a fields value if a condition is met.

Here is the screenshot:
http://awesomescreenshot.com/04b38azj3e

That "Days Pending" column is created from this script within the custom default_row.php:

Code:
if ($heading == 'tblecn___pending') {  // Days Pending: Days Open Since Date Initiated  NOW() - $date_iniated = Pending Date
           
                //now!
                $now = time();
           
                // Pull the Date Initiated, which doesn't change after ECN is edited
           
                $date_initiated = $val[0]->date_time;
           
                // Turn the variable for date into a date string
                $date_initiated = strtotime($date_initiated);
           
                // Create a variable to show the difference between the two
                $datediff = abs($now - $date_initiated);
           
                // Show how many days the ECN has been up!
                echo floor($datediff/(60*60*24)) . ' Days';
   
            }

I need to find a way to take this script from the default_row and calculate when a record is 14 days or older to automatically change an approval from " " to "Yes".

May I get a little guidance on how to do an UPDATE query in a form php script?


Pseudo Script:

If created date is greater than 14 days (pending) and approval == "", then UPDATE approval == "Yes"
 
Is approval an element in your tblecn list? Something like
Code:
$id =$this->_row->data->tblecn___id_raw ;
if ($datediff > 14 && $this->_row->data->tblecn___approval =="" )
{
// Get the db object
$db = JFactory::getDbo();
 
// Build the query ? Tables names = CASE SENSITIVE
$query = $db->getQuery(true);
 
$query
      -> update('tblecn')
      -> set('approval="Yes"')
      -> where('id = '. (int) $id);
 
$db->setQuery($query);
$result = (int) $db->query();
}
 
  • Like
Reactions: rob
Hi Troester, yes it is a field in the form. There are no database joins.

So I was looking at the Form and looks like the code won't work in form processing. This script needs to happen without even opening a form. It should work automatically in 14 days.

I just put the code in default_row dot php file and IT WORKED.

THANK YOU THANK YOU THANK YOU. What a life saver the Fabrik team is.

I love you guys!
 
In default_row.php it will only be run if the list is displayed.
If you want to do something like this automatically add a scheduled task (php plugin).
 
In default_row.php it will only be run if the list is displayed.
If you want to do something like this automatically add a scheduled task (php plugin).

I've never used a scheduled task so I'm a bit hesitant to learn something new!

It should only run when a person views a list anyways because it changes the cell "green" when it's approved, so it's a visual thing :)

So thanks, it works exactly how it should!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top