Insert date_time upon save on a list

Geoff Cloake

New Member
Hi there,

I'm trying to figure out how i can insert the date_time into a fabrik list when something is being uploaded and the radio button is chosen. Is there a javascript or PHP code that can do the above? Please see below for better illustration:

fabrik_list.png
 
When you say "and the radio button is chosen" ... a radio button is always chosen, that's the nature of radio buttons. So I'm not quite sure how to interpret that.

-- hugh
 
If you just want the last edit time, select "Always return today's date" in the date options.

But I think, combining you last reply with the original post, what you probably want is to update the element only when it's corresponding upload element is uploading a file. Which is a bit trickier. There's nothing built in to do it, so you'd have to do it in a PHP form submission plugin, which checks the file inputs for the three uploads, and sets the co responding date as required.

Before I spend any time helping out with code to do that, can you confirm that's what you want.

-- hugh
 
OK, then you need a form PHP plugin. Running on "both" (where and when), process "onBeforeStore". PHP code something like this:

Code:
$myFile = $this->app->input->files->get('yourtable___upload, array());
if (array_key_exists('name', $myFile) && !empty($myFile['name'])) {
  $formModel->updateFormData('yourtable___datetime', date('Y-m-d H:i:s'), true);
}

... which would set the 'yourtable___datetime' element if the 'yourtable___upload' element has a file being uploaded.

One thing that isn't clear from your post is whether that's three separate sets of elements, or three repeats in a repeat group. If it's three separate groups of elements, then just duplicate that code two more times (so you have essentially the same lines 3 times, and change the element names to suit.

If it's a repeat group, use this instead:

Code:
$myFiles = $this->app->input->files->get('yourtable___upload, array());
foreach ($myFiles as $myIndex => $myFile) {
   if (array_key_exists('name', $myFile) && !empty($myFile['name'])) {
     $formModel->formData['yourtable___datetime'][$myIndex] = date('Y-m-d H:i:s');
     $formModel->formData['yourtable___datetime_raw'][$myIndex] = date('Y-m-d H:i:s');
   }
}

-- hugh
 
Hi there,

When i try to execute that code it doesn't update the date and time in the new column under the same table. When i check what's in $myFile variable, i get an empty key and value in the array as per attached. Would it be something wrong with the fileupload element that i created?

empty_array.png
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top