Laravel: textarea does not replenish when using Input :: old

I feel that only text input fields respond as expected when I write code to re-fill the form (when errors were found, for example), or when I click the "Edit" button from the table row and I go to the form that is being edited, The field for the text field is not populated, so it appears empty, so if I save it, I will delete the contents of the text field. (I know that recently I have been asking a number of questions, the reason is that I basically finished my application, and I left for the end small things that I could not solve, so I apologize for this).

here is an example of what i am saying:

This WORKS to enter a text field:

WORKS

<div class="col-md-4"> <label for="relato">Charges</label> <input type="text" name="expenses" maxlength ="30" class="form-control" value = "{{ $user->expenses }}"/> </div> 

That is, $ user-> costs fills the text field of the form that appears when you click the "Edit" button in the table row.

However, this does not work for the textarea field:

 <div class="row"> <label for="relato">Description</label> <textarea name ="message" id="message" rows="5" cols="100" value = "{{ $user->message }} class="form-control" </textarea> </div> 

Cm? that part of $ user-> message will not pass content to the form text field.

Similar: with Input :: old

Works for text input field

WORKS

  Email: <input type="text" class="form-control" name="email" {{ (Input::old('email')) ?' value ="' . e(Input::old('email')). '"' : '' }}> 

DOES NOT WORK IN TEXTAR

 <div class="form-group"> <label for="relato">Une petite description</label> <textarea id="message" name = "content" rows="10" cols="50" onKeyPress class="form-control" {{ (Input::old('content')) ?' value ="' . e(Input::old('content')). '"' : '' }} "> </textarea>{{ $errors->first('content')}} </div> 

And the controller also tries to replenish the form by sending β†’ withInput

  if($validator->fails()){ return Redirect::route('usersgetformtopostads') ->withErrors($validator) ->withInput(); } 

but, as I said, it only works for text fields. Does not change the list of favorites or text files

By the way, I looked at a related question, where the author says that he could not populate the "File" field, and he was told that "you can not", and he gave it as the correct answer, however, I was able to repopulate uploaded files having no problem with this.

+7
laravel
source share
5 answers

textarea does not have a value attribute. The values ​​in textarea must be inside <textarea></textarea> , so in your case:

 <textarea id="message" name = "content" rows="10" cols="50" onKeyPress class="form-control"> {{{ Input::old('content') }}} </textarea> 
+34
source share

This is another way to do the same, but with the Forms component from laravel:

 {{ Form::textarea('content',Input::old('content'),array('id' => 'message')) }} 
+4
source share

I would like to add one thing, if you use the Form Class for the form and elements, then you do not need to explicitly reference Input :: old ('element-name') to get the value of the previous representation of the form.
Just use
{{ Form::text('name', null, array('id'=>'name', 'class' => 'class-to-apply')) }}
And you are good to go.

Here, the null value for the text field will be empty for the first time, and if you redirect this page with input, it will automatically capture the value.

+1
source share

Just realized put the old value between the brackets below

 <textarea name="message">{{ old('message') }}</textarea> 
+1
source share

sorry for the late reply

 {{Form::textarea('mobile_message', isset($notifications -> mobile_message) ? $notifications -> mobile_message : null, 'id'=> 'mob_id','class' => 'form-control'))}} 
0
source share

All Articles