Laravel:使用Input :: old时textarea无法重新填充 [英] Laravel: textarea does not refill when using Input::old

查看:138
本文介绍了Laravel:使用Input :: old时textarea无法重新填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,当我编写重新填充表单的代码(例如,发现错误)或从表行中单击编辑"按钮并转到可编辑表单时,只有输入文本字段会按预期方式响应. textarea的字段未重新填充,因此显示为空,因此,如果我保存它,则将删除textarea的内容. (我知道最近我要问一系列问题,原因是我已经基本完成了我的申请,我把无法解决的小事留给了最后,为此我深表歉意.)

I am experiencing that only the Input Textfields respond as expected when I write the code to repopulate a form (when errors were found for example) or when from a table row I click in the Edit button and I go to an editable form. The field for a textarea is not repopulated so it comes up empty, therefore, if I save it, I would delete the content of the textarea. (I know I am asking a succession of questions lately, the reason is that I have basically finished my application and I left for the end the minor things I could not solve, so my apologies for that).

这是我在说什么的例子:

here is an example of what I am saying:

此输入文本字段的工作方式:

This WORKS for input textfield:

作品

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

也就是说,$ user-> expenses会填充单击表行的Edit按钮时出现的表单的文本字段.

That is, the $user->expenses fills the textfield of the form that comes up when clicking the Edit button of a table row.

但是,这不适用于textarea字段:

However, that does not work for a 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>

看到了吗? $ user-> message部分不会将内容传递到表单的文本区域.

See? that part $user->message will not pass the content to the textarea of a form.

类似地:使用Input :: old

Similarly: with Input::old

适用于输入文本字段

作品

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

不适用于TEXTAREA

DOES NOT WORK FOR TEXTAREA

<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>

并且控制器还尝试通过发送-> withInput

And the controller is also trying to refill the form by sending ->withInput

 if($validator->fails()){

           return Redirect::route('usersgetformtopostads')

                        ->withErrors($validator)

                        ->withInput();                           

                        } 

但是,正如我所说,它仅适用于文本字段.不会为我重新填充选择列表或文本框

but, as I said, it only works for textfields. Does not repopulate me a select list or a textrarea

顺便说一句,我在这里看了一个相关的问题,作者说他不能重新填充文件"字段,并被告知您不能",他给出了正确的答案,但是,我能够重新填充上传的文件,没有任何问题.

By the way, I have looked a related question here where the author says he could not repopulate a File field and he was told that "you cant" and he gave that as a correct answer, however, I have been able to repopulate Files uploaded, not having any problem with that.

推荐答案

textarea没有value属性. textarea中的值应在<textarea></textarea>内,因此在您的情况下:

textarea does not have a value attribute. Values in textarea should 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>

这篇关于Laravel:使用Input :: old时textarea无法重新填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆