Forums

How to save Datepicker data into DB

hoekbrwr 12 Sep, 2014
I have a form with a Datepicker field and a DB field of type DATE. I am not able to store any date type or numeric type into the database. A string field just stores OK. What should be done to get those data stored also?😶
GreyHead 12 Sep, 2014
Hi hoekbrwr,

If your form is submitting a date in a string format that MySQL will recognise it should save OK as a type date, What is being submitted now?

Bob
hoekbrwr 12 Sep, 2014
I just click the Datepicker graphic and leave it untouched further. It is in the format d-m-Y format as defined in the settings.
GreyHead 12 Sep, 2014
Hi hoekbrwr,

And MySQL won't recognise that as a DATE . . . so either you need to change the format in the datepicker, or use a Custom Code action to convert the string after the form is submitted but before the data is saved.

There's more in the MySQL manual here.

Bob
hoekbrwr 12 Sep, 2014
When I use the mask setting Integer for a supposedly integer input field I see a change in my input field. It is now right adjusted signing a numeric value to use. However I cannot input any number!
GreyHead 12 Sep, 2014
1 Likes
Hi hoekbrwr,

Please post a different topic in a new thread. so far ChronoForums won't let me split threads :-(

Bob
hoekbrwr 12 Sep, 2014
This is not so user friendly! If you use a Datepicker Box you have to use extra code to get that element functioning. This means for every format you need to have a Custom code. It should have been integrated with the Datepicker Box code. Only few people are fluent in using Custom code and I am not one of them! It is not an option to show another format as usual in my country, different from the database format.
GreyHead 12 Sep, 2014
Hi hoekbrwr,

True, it could be better, maybe that will get fixed in a future version. I don't remember anyone else asking this question so it probably isn't high on Max's list though.

Please see this StackOverFlow answer for an example of the code you need.

Bob
hoekbrwr 12 Sep, 2014
Answer

Hi hoekbrwr,

And MySQL won't recognise that as a DATE . . . so either you need to change the format in the datepicker, or use a Custom Code action to convert the string after the form is submitted but before the data is saved.

There's more in the MySQL manual here.

Bob



The only format in Chronoforms which MySQL understands is YYYmmDD or alike. That is not an option for my country!
Max_admin 12 Sep, 2014
Hi,

The format which mySQL understands is Y-m-d, which is not suitable in all situations, but that's how it is, and if you want to save your form date in this format then you must place the code to do this, for most common formats, you can use the strtotime function:
$form->data["date"]  = date("Y-m-d", strtotime($form->data["date"]));


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
hoekbrwr 12 Sep, 2014
If it is that "easy" why not integrating it in the DBSave action?
Max_admin 13 Sep, 2014
because its dependent on the date field name and format, this is very ambiguous to account for!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.