【问题标题】:Laravel form with <div> tags in the middle中间有 <div> 标签的 Laravel 表单
【发布时间】:2018-01-04 04:02:58
【问题描述】:

我正在尝试使用中间带有 div 标签的表单。但是,它似乎不起作用,在没有它们的情况下使用表单可以正常工作。有什么方法可以对表单进行样式化并使用它吗?

{!! Form::open(['action' => 'ProductController@store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<div class="centre col-lg-4 col-lg-offset-4 ">
  <h2>Product</h2>
  {{Form::text('', '', ['class' => 'form-control', 'placeholder' => 'Product'])}}
</div>
<div>
  <div class="section3  ">
    <div class="container centre">
      {{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
    </div>
  </div>
</div>
{!! Form::close() !!}

【问题讨论】:

  • 你可以使用没有Form外观的表单标签
  • &lt;div&gt;的目的是什么
  • @HoàngĐăng 使元素居中并制作列。
  • 你的意思是你的css在插入div标签时坏了
  • @HoàngĐăng 当我使用 div 标签并按下按钮时,表单不会提交。否则很好

标签: php html css laravel


【解决方案1】:

您的代码中有一些不需要的&lt;/div&gt;,导致表单在错误的位置关闭,修复&lt;div&gt;,它将重新开始工作。基本上,这是由于代码格式不正确造成的错误。

<div>
        {!! Form::open(['action' => 'ProductController@store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}

   <div class="centre col-lg-4 col-lg-offset-4 ">
            <h2>Product</h2>
            {{Form::text('', '', ['class' => 'form-control', 'placeholder' => 'Product'])}}
    </div>
     <div class="section3  ">
        <div class="container centre">

            {{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
            {!! Form::close() !!}
        </div>
    </div>
</div>

并且不要忘记在您的代码中添加名称和其他参数以使您的表单有价值。

{{Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Product'])}}

【讨论】:

    【解决方案2】:

    首先 div 标签没有正确关闭 ..您在第一个 div 中有两个不需要的标签。 您可以根据您的设计需要进行样式设置。

    <div class="container">
      <div class="well">
    
    {!! Form::open(['action' => 'ProductController@store', 'class' => 'form-inline' , 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
    
    <fieldset>
    
        <div class="form-group">
            {!! Form::label('product', 'Product:', ['class' => 'col-lg-2 control-
           label']) !!}
            <div class="col-lg-10">
                {!! Form::text('product', $value = null, ['class' => 'form-
                 control', 'placeholder' => 'product']) !!}
            </div>
        </div>
    
        <!-- Submit Button -->
            <div class="form-group">
             <div class="col-lg-10 col-lg-offset-2">
                {!! Form::submit('Submit', ['class' => 'btn  btn-info '] ) !!}
             </div>
            </div>
    
    </fieldset>
    
    {!! Form::close()  !!}
    
      </div>
    </div>
    

    您可以使用 bootsrap html 表单进行简单和更好的设计,因为它们针对不同的设计具有不同的表单类。

    https://www.w3schools.com/bootstrap/bootstrap_forms.asp

    如果你觉得这有帮助

    【讨论】:

      【解决方案3】:

      表单关闭标签的深度应与表单打开标签的深度相同:

      没有他们。有什么方法可以对表单进行样式化并使用它吗?

      {!! Form::open(['action' => 'ProductController@store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
      <div>
          <div>
      
             <div class="centre col-lg-4 col-lg-offset-4 ">
                      <h2>Product</h2>
                      {{Form::text('product', $value=null, ['class' => 'form-control', 'placeholder' => 'Product'])}}
              </div>
          </div>
      </div>
      
      <div>
          <div class="section3  ">
              <div class="container centre">
      
                  {{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
      
              </div>
          </div>
      </div>
      {!! Form::close() !!}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-03-22
        • 2016-07-28
        • 1970-01-01
        • 2018-07-19
        • 2014-08-22
        • 1970-01-01
        • 2021-06-11
        相关资源
        最近更新 更多