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