Justin
Justin

Reputation: 105

laravel have both Input::old('') and value of text input on form

I have a form that will pull data from the database as well as submit new data to overwrite the old all in the same fields. For example:

{{ Form::text('date', Input::old('date'),  array('id' => 'date'))}}

Where the second parameter includes both the value from the database $i->date and also the input:old validator to ensure it wasn't left blank by accident.

Is there a way to do this? I already tried using an array as the second parameter.

Upvotes: 1

Views: 4920

Answers (2)

Mark
Mark

Reputation: 3197

Not exactly sure what you are trying to do but will this work?

Form model binding

{{ Form::model($yourmodel, array('route' => array('yourmodel.update', $yourmodel->id))) }}

{{ Form::text('date', Input::old('date'), null, array('id' => 'date')) }}

from the docs

If there is an item in the Session flash data matching the input name, that will take precedence over the model's value. So, the priority looks like this:

Session Flash Data (Old Input) Explicitly Passed Value Model Attribute Data

Upvotes: 0

revo
revo

Reputation: 48741

Yes, you should consider form model binding Form::model instead of Form::open.

Also you can leave your input value alone:

{{ Form::text('date', null,  array('id' => 'date'))}}

Controller side example:

$model = new Model;
return View::make('layout', compact('model'));

Way of opening the form:

{{ Form::model($model) }}

Upvotes: 2

Related Questions