Jump to content


field_type hidden and field_type date problem

hidden field_type date

  • Please log in to reply
9 replies to this topic

#1 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationHolguín, Cuba

Posted 02 August 2013 - 01: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

 



#2 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 02 August 2013 - 03:50 PM

Which version of Grocery CRUD are you using?


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#3 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationHolguín, Cuba

Posted 02 August 2013 - 04:02 PM

i use GC 1.3.3



#4 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 02 August 2013 - 10:56 PM

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


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#5 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationHolguín, Cuba

Posted 05 August 2013 - 02: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"



#6 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 05 August 2013 - 02:41 PM

I honestly don't know!


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#7 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationHolguín, Cuba

Posted 05 August 2013 - 03:10 PM

ok, thank you anyway!



#8 mnish

mnish

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationIndia

Posted 31 August 2013 - 05:24 PM

can you show your table schema.?

 

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



#9 edramirez

edramirez

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts
  • LocationMetro Manila

Posted 12 November 2013 - 01: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.



#10 jeanjunker

jeanjunker

    Member

  • Members
  • PipPip
  • 12 posts

Posted 31 August 2017 - 06: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.







Also tagged with one or more of these keywords: hidden, field_type, date

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users