Robin
Robin

Reputation: 1587

Laravel date picker gives wrong value on post and gives wrong year

I'm using materializecss framework for my new application. I also use the pickdate function in javascript.

What I want to do is, let user choose their birthday and put them as an datetime format inside of the database.

As nuw I have an input

{{ Form::text('datum', Input::old('datum'), array('id' => 'datepicker', 'class' => 'datepicker')) }}

That works fine and gives me the correct input.

But When I open the picker, it shows the dates from now (2015) untill 2005...

But I want to let them choose their date from 1960 untill now.

Hop U get that?

Okay,

When I try to input the values Let's say July 17'th 2013, and I want them in my database as an datatime format so 2013-7-17 00:00:00.

Now, It gives (when I var_dump) this format: ["datum"]=> string(21) "wednesday 17 july 2013". But that's not what I want.

I have a file where I 'rewrite' the main functions That looks like this:

$('.datepicker').pickadate({

    // Strings and translations
    monthsFull: ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'october', 'november', 'december'],
    monthsShort: [ 'jan', 'feb', 'maa', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec' ],
    weekdaysFull: [ 'zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag' ],
    weekdaysShort: [ 'zo', 'ma', 'di', 'wo', 'do', 'vr', 'za' ],
    showMonthsShort: [ 'Z', 'M', 'D', 'W', 'D', 'V', 'Z' ],
    showWeekdaysFull: undefined,

    // Buttons
    today: 'vandaag',
    clear: 'verwijder',
    close: 'sluit',

    // Accessibility labels
    labelMonthNext: 'Volgende maand',
    labelMonthPrev: 'vorige maand',
    labelMonthSelect: 'selecteer een maand',
    labelYearSelect: 'selecteer een jaar',

    // Formats
    format: 'dddd d mmmm yyyy',
    formatSubmit: 'm-d H:i:s',
    hiddenPrefix: undefined,
    hiddenSuffix: '_submit',
    hiddenName: undefined,

    // Editable input
    editable: undefined,

    // Dropdown selectors
    selectYears: true,
    selectMonths: true,

    // First day of the week
    firstDay: 1,

    // Date limits
    min: false,
    max: true,

    // Disable dates
    disable: undefined,

    // Root picker container
    container: undefined,

    // Hidden input container
    containerHidden: undefined,

    // Close on a user action
    closeOnSelect: true,
    closeOnClear: true,

    // Events
    onStart: function() {
    //
  },
  onRender: function() {
    //
  },
  onOpen: function() {
    //
  },
  onClose: function() {
    //
  },
  onStop: function() {
    //
  },
  onSet: function(context) {
    //
  }

  });

I don't know what I'm doing wrong, or how I can solve this issue..

Kindest regards,

Robin.

Upvotes: 0

Views: 966

Answers (2)

Robin
Robin

Reputation: 1587

The problem what the format I was using.

This worked for me:

format: 'dddd d mmmm yyyy',
formatSubmit: 'yyyy-mm-dd',
hiddenPrefix: undefined,
hiddenSuffix: '_submit',
hiddenName: 'datum',

Still thanks to you guys, but A friend of mine knew the problem.

Upvotes: 0

Kamil Szymański
Kamil Szymański

Reputation: 950

I'm not sure, but it looks like you made a typo:

// Formats
format: 'dddd d mmmm yyyy',
formatSubmit: 'm-d H:i:s', //Y-m-d H:i:s
hiddenPrefix: undefined,
hiddenSuffix: '_submit',
hiddenName: undefined,

Also in docs you can see:

the value that needs to be sent to the server is just the hidden value – and not the visible one. To make this happen, use the hiddenName option

so set it to:

hiddenName: true

I'd say to set both suffix and prefix values for hidden field to "" and make sure, that in backend part you catch a proper input field (docs says it's set to date_input by default).

Upvotes: 1

Related Questions