⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

field_type hidden and field_type date problem



kenshicu

kenshicu
  • profile picture
  • Member

Posted 02 August 2013 - 13:47 PM

$crud->fields('field1','field2','field3','field4');

$crud->field_type('field1', 'hidden');
$crud->field_type('field2', 'hidden');
//$crud->field_type('field3', 'date');
$crud->field_type('field4', 'hidden');

when editing a record,

where "field3" is of type date, I put the value: 2013-08-02

but to make a callback_before_update in post_array ['field3'] is saved: 02/08/2013, rather than: 2013-08-02

I think it is because I put the other fields, hidden type


I solved it in the callback_before_update adding:

$date_array = preg_split( '/[-\.\/ ]/', post_array['field3']);
post_array['field3'] =  date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2]));
return $post_array;

I think the library grocery_crud.php, has a small bug on this.
perhaps somewhere, does not run the function: _convert_date_to_sql_date($date)


regards

 


davidoster

davidoster
  • profile picture
  • Member

Posted 02 August 2013 - 15:50 PM

Which version of Grocery CRUD are you using?


kenshicu

kenshicu
  • profile picture
  • Member

Posted 02 August 2013 - 16:02 PM

i use GC 1.3.3


davidoster

davidoster
  • profile picture
  • Member

Posted 02 August 2013 - 22:56 PM

What value do you have on $config['grocery_crud_date_format'] setting which is at application/config/grocery_crud.php?


kenshicu

kenshicu
  • profile picture
  • Member

Posted 05 August 2013 - 14:08 PM

i have

$config['grocery_crud_date_format']            = 'uk-date';

 

but also works well, when not in use, hidden type fields.

i try change for "sql-date"


davidoster

davidoster
  • profile picture
  • Member

Posted 05 August 2013 - 14:41 PM

I honestly don't know!


kenshicu

kenshicu
  • profile picture
  • Member

Posted 05 August 2013 - 15:10 PM

ok, thank you anyway!


mnish

mnish
  • profile picture
  • Member

Posted 31 August 2013 - 17:24 PM

can you show your table schema.?

 

I think problem is in your table schema not in Grocery Crud. Crud is Awasome.


edramirez

edramirez
  • profile picture
  • Member

Posted 12 November 2013 - 13:54 PM

In order to change the date format from 2013-01-31 to 01/31/2013, you need to open the grocery_crud.php file in the config folder. Look at line number 6.

 

Change the setting so that it looks like this:

 

$config['grocery_crud_date_format'] = 'us-date';

 

Keep in mind that this change applies to grocerycrud operations only. When you do input operations outside of grocerycrud, you will notice that the format might be different. There is a way to set this correctly using the built-in jquery library. But that's another topic which I can share with you in another post, if you are interested to know.

 

 

 

Regards,

 

Ed Ramirez

 

P.S. Don't forget to click the Like button.


jeanjunker

jeanjunker
  • profile picture
  • Member

Posted 31 August 2017 - 18:25 PM

I recently had a similar issue with a hidden DATE field that would not save to the database but all my debugging code showed that I was populating it correctly and another DATE field that was NOT hidden was the one that I was forcing into the hidden date field and they both looked fine in my debuting "log message" code.

 

I was about to post that there was a "bug" in GroceryCRUD, but NOT SO.

I finally figured out what to do to make it work after about 2-3 hours...

 

Apparently GC does some SQL Date formatting internally when you use its DATE picker dialog even though my GC config setting was for 'us-date' and the date displayed as mm-dd-yyyy as I expected.

However GC must reformat the date to a SQL-Date before the INSERT/UPDATE i guess it only does the on dates it has "seen" on the user form not hidden fields.

 

I manually formatted the hidden DATE fields value to the SQL-date format (yyyy-mm-dd) and VOILA that solved the problem, it now saved to the My-SQL DB correctly.

 

Maybe this answer helps someone else...

Jean.