1

I'm using Laravel Collective Forms & HTML. I have a form field that looks like this:

<div class="md-form" >
    {!! Form::text('date', (!empty($entry['date_submit']) ? $entry['date_submit']->format('M j, Y') : null), ['class' =>'date-time form-control datepicker ' . ($errors->has('date_submit') ? ' validate invalid' : '' )]) !!}
    {!! Form::label('date', 'Select a date') !!}
</div>

I'm also using MDBootstrap for the look and feel. This creates a material design style date picker and adds a hidden field called date_submit that stores the selected date. This means when I'm processing the form, I actually have to add the following line to compensate:

    $input = $request->all();
    $input['date'] = $input['date_submit'];

Fine, no problem.

I'm also using a Request for all my validation, so the form returns before touching the store method if the validation fails. The validation works fine, no problems.

The problem is that when the validation fails but the date is recorded, it prefills the date field with 'undefined undefined' rather than the date as entered (because the date field names don't match).

So far this is an issue with date and time fields as they both have nice material design selectors within MDBootstrap.

  • Is there a way to tell the Form::text to use a different field name for the input value (date_submit instead of date) while still leaving the field name as date
  • Should I be looking at a different way of processing the validation instead of by using Requests?
TH1981
  • 3,105
  • 7
  • 42
  • 78
  • Is there a reason you're changing the name of the input? Also, what format is the date format when it is submitted? – Rwd Oct 28 '16 at 23:12

0 Answers0