英文:
Display textarea value in Laravel
问题
I have posts. When I click edit it takes me to the edit screen and display current post values. However for some reason the input is displayed while textarea is not. I can't understand why.
Works perfectly, displays value.
It doesn't display value for body.
英文:
I have posts. When I click edit it takes me to the edit screen and display current post values. However for some reason the input is displayed while textarea is not. I can't understand why.
Works perfectly, displays value.
<input class = "form-control" type="text" name = 'body' value = "{{ old('body', $post->body ?? null) }}" />
It doesn't display value for body.
<textarea class="form-control" type="text" name = 'body' rows="3" value = "{{ old('body', $post->body ?? null) }}" ></textarea>
答案1
得分: 4
输入是自闭合标签,这就是为什么在输入中你可以通过 value=
来设置值,而在文本区域中有闭合标签,这就是为什么在文本区域中你不能通过 value
属性来设置值。
<textarea class="form-control" type="text" name = 'body' rows="3"> {{ old('body', $post->body) }}</textarea>
英文:
input is self closing tag that's why in input you can set value via value=
and in textarea there is closing tag that's why in textarea you can't set value via value
attribute
<textarea class="form-control" type="text" name = 'body' rows="3"> {{ old('body', $post->body) }}</textarea>
答案2
得分: 1
textarea标签没有值,但在handlebars中可以正常工作。它具有占位符属性,但在这里不像这样工作:https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-placeholder
因此,只需在闭合标签之前提供值
<textarea class="form-control" type="text" name='body' rows="3">{{ old('body', $post->body ?? null) }}</textarea>
英文:
The textarea tag has no value, but work fine with handlebars.it has placeholder attribute but here it not work like this https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-placeholder
So just give the value before close tag
<textarea class="form-control" type="text" name = 'body' rows="3" >{{ old('body', $post->body ?? null) }}</textarea>
答案3
得分: 0
<div class="form-group col-md-6">
<label class="control-label">Vendor Description</label>
<textarea name="dec" class="form-control" rows="3" value="{{ old('dec') }}"></textarea> {!! $errors->first('dec', '<p class="text-danger errorBag">:message</p>') !!}
<label class="control-label">Last Name</label>
<input type="text" name="l_name" class="form-control" value="{{ old('l_name') }}"> {!! $errors->first('l_name', '<p class="text-danger errorBag">:message</p>') !!}
</div>
英文:
**Display textarea value in Laravel
<div class="form-group col-md-6">
<label class="control-label">Vendor Description</label>
<textarea name="dec" class="form-control" rows="3" value="{{old('dec')}}"></textarea> {!! $errors->first('dec', '
<p class="text-danger errorBag">:message</p>') !!}
<label class="control-label">Last Name</label>
<input type="text" name="l_name" class="form-control
" value="{{old('l_name')}}"> {!! $errors->first('l_name', '
<p class="text-danger errorBag">:message</p>') !!}
</div>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论