Help with date_time filed

Ivan4o0o

Member
Hi
So I have a small form with a date_time field with format m-d-Y. I have a php plugin with the form that redirects to another form and adds the date_time field value to the redirect url.
In the other form there is another date_time field with format m-d-Y and its value must be set from the URL (with the value of the date_time element of the first form).
This almost work, but the problem is that Fabrik tries to convert the value from the URL to d-m-Y format and it breaks.
Code:
 DateTime::__construct(): Failed to parse time string (07-21-2016) at position 0 (0): Unexpected character

Can somebody give me some directions how to do this.
P.S. I cannot change the locales of the server.
 
Hi,

Have you tried putting it as d-m-Y on the URL and then setting your format code on the receiving field back to m-d-Y?

Paul
 
Hi Paul
I have tried to do this tith a php plugin on the form that changes the value before the form is submitted but I am doing something wrong maybe and it is not working. I don't know how to send the date in the URL in d-m-Y.
I have tried this:
PHP:
$oldDate = $formModel->formData['___date_time'];
$oldDate = substr($oldDate,0,10);
$arr = explode('-', $oldDate);
$newDate = $arr[2].'-'.$arr[1].'-'.$arr[0];
//var_dump ($newDate); exit;
$formModel->updateFormData("___date_time", $newDate , true);
 
Mhm, are you actually getting the $oldDate, since that does not look like a valid field name. It seems to be missing the group name.

How are you trying to do the redirect part then? I was assuming that you would be doing that somehow manually.

Anyhow, assuming you have that all figured out, and me not being familiar with the php form plug-in. I am guessing, that you are not allowed to change your format before submitting. I has to be in a format the DB understands and expects.

Sorry not much help here, I leave this up to the experts.
 
Assuming the form is "table-less" (doesn't save to the database), then the element name is correct (it won't have a table name prefix, just ___).

I assume you also have a redirect on the form, which is where you add the &yourtable___date_time={___date_time}

I think you are probably running into issues with the date element pre-processing. We go to great lengths to standardize the date format during submission to the MySQL format. So the date element assumes that submitted data is in "Y-m-d H:i:s" format. Seting it to anything else will confuse the poop out of it.

So you may need to bypass all that entirely, and do the redirect yourself in your PHP plugin code. Manually grab all the data you need form formData[], build the URL, then do something like ...

Code:
$this->app->redirect($url);

I think $this->app should exist at that point, if not ...

Code:
JFactory::getApplication()->redirect($url);

-- hugh
 
Assuming the form is "table-less" (doesn't save to the database)
- Yes this is true.
I assume you also have a redirect on the form, which is where you add the &yourtable___date_time={___date_time}
- Yes.This is exactly what I do.

Great help. This works: $this->app->redirect($url);

Thanks a lot.

Ivan
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top