【问题标题】:Laravel 5.7: Laravel Collective Form to html formLaravel 5.7:Laravel 集体表单到 html 表单
【发布时间】:2020-11-19 09:50:03
【问题描述】:

我有以下 laravel 集体表单代码

{!! Form::open(['action' => ['CategoryController@sub8', $item1->id], 'method' => 'post']) !!}
{{Form::label('postaladdress', 'Postal Address')}}
{{Form::text('postaladdress',null, array('class' => 'form-control'))}}
{{ Form::hidden('_method', 'PUT') }}

{{ Form::submit('Change Postal Address') }}
{!! Form::close() !!}

我怎样才能以正常的 html 形式获得这个?

【问题讨论】:

  • 查看生成页面的源代码(或检查元素)得到“正常的html表单”
  • 谢谢,但不幸的是我无法使用 laravel 集体加载页面
  • 为什么会这样?使用集体表单时是否遇到任何错误?
  • 每个方法都会渲染一个元素,例如<form><label><input type='text'/><input type='hidden'/><input type='submit'> (或<button>)和</form>。您应该能够查看这些并将它们反向工程为基础 HTML 元素。你试过什么吗?请记住,Stackoverflow 不是代码编写服务,您应该在发布之前努力解决自己的问题。
  • CTRL + U 并使用代码

标签: php html laravel forms


【解决方案1】:

您应该能够根据 HTML 标记的内容弄清楚这一点,但为了节省您自己的时间,这大致是这样的:

<form method="POST" action="{{ action('CategoryController@sub8', [$item1->id]) }}">
    <input type="hidden" name="_method" value="PUT">
    <label for="postaladdress">Postal Address</label>
    <textarea name="postaladdress" class="form-control"></textarea>
    <input type="submit" value="Change your address">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>

我忘记了 Laravel Collective - HTML 是否会为你添加 CSRF 令牌,但我还是在上面的示例中添加了它。

【讨论】:

    猜你喜欢
    • 2019-03-01
    • 2017-03-15
    • 2017-04-05
    • 2021-07-26
    • 1970-01-01
    • 2019-08-29
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多