【问题标题】:Only the last values are submit仅提交最后一个值
【发布时间】:2020-11-15 04:22:42
【问题描述】:

在绘制数值的页面,将数值输入到不同的字段后,只传递最后一个。

应该有 eg: 对于值 v1, v2, v3, v4, v5 和组 g1, g2 示例结果应该是 g1: v1, v3; g2:v2、v4、v5

其实就是:g2: v5 来自上面的例子。

我在哪里犯了错误?我是初学者,所以代码中可能存在无意的错误。这是我的代码。

输入值。按下按钮时会出现新字段。

<div class="mx-auto position-relative form-wrapper">
            <form method="post" id="form" action="{{route('randomizeValues.store')}}" name="form" class="form text-center"
                data-response-message-animation="slide-in-left" novalidate>
                @csrf
                <div id="parent" class="list-group">
                    <div class="form-group form-filed horizontal">
                        <input name="values" class="input" type="text" autocomplete="off" placeholder="Enter value"
                            autofocus onkeypress='validate(event)' onkeydown="pressEnter(event)" required>
                    </div>
                </div>
                <div id="parent" class="list-group">
                    <div class="form-group form-filed horizontal">
                        <input name="groups" class="input" type="text" autocomplete="off" placeholder="Enter group"
                            autofocus onkeypress='validate(event)' onkeydown="pressEnter(event)" required>
                    </div>
                </div>
                <button type="submit" class="btn btn-lg btn-alternate align-center">Draw</button>

在表格中显示结果。

<div class="section-heading text-center">
                <h2>The following groups of results were drawn:</h2>
                @foreach ($values_json as $value => $val)
                <table class="table table-responsive">
                    <thead>
                        <tr>
                            <th style="width: 16.66%" scope="col">{{$value}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($val as $v)
                        <td> {{$v}}
                            {{$loop->last? "": "  &nbsp; " }} </td>
                        @endforeach
                    </tbody>
                </table>
                @endforeach
                <form method="post" id="form" action="{{route('randomizeValue.store')}}" name="form"
                    class="form text-center" data-response-message-animation="slide-in-left" novalidate>
                    @csrf
                    <button type="submit" class="btn btn-lg btn-alternate align-center">Draw again</button>
                    <a href="/randomizeValue" id="destroySession" type="submit"
                        class="btn btn-lg btn-alternate align-center">Cancel</a>
                </form>
            </div>
                </form>
            </div>

【问题讨论】:

    标签: javascript css laravel laravel-blade


    【解决方案1】:

    您忘记在&lt;tbody&gt; 中连续添加内容。只需在 &lt;td&gt; 旁边添加 &lt;tr&gt;&lt;/tr&gt;

                    <tbody>
                        @foreach($val as $v)
                        <tr>
                            <td> {{$v}} {{$loop->last? "": "  &nbsp; " }} </td>
                        </tr>
                        @endforeach
                    </tbody>
    

    【讨论】:

    • 感谢您的建议,但问题仍然存在。
    • 它仍然只显示 g2: v5?
    • 不幸的是,但是是的。也许问题在于处理值?
    • 这将是我的下一个想法。请您分享您的控制器吗?
    • 请尝试dd()这些值并粘贴它们
    【解决方案2】:

    试试这个

         <div class="section-heading text-center">
                <h2>The following groups of results were drawn:</h2>
               
                <table class="table table-responsive">
                    <thead>
                        <tr>
                            <th style="width: 16.66%" scope="col">{{$value}}</th>
                        </tr>
                    </thead>
                    <tbody>
                      @foreach ($values_json as $value => $val)
                          @foreach($val as $v)
                             <td> {{$v}} {{$loop->last? "": "  &nbsp; " }} </td>
                          @endforeach
                      @endforeach 
                    </tbody>
                </table>
               
    

    【讨论】:

      【解决方案3】:

      看起来你有嵌套的表单,除非你使用 JS 来处理提交,否则这是一个禁忌。

      我建议您从第一种形式中获取第二种形式并尝试这种方式。 您可以在此处阅读有关表单元素的更多信息:https://html.spec.whatwg.org/multipage/forms.html#the-form-element

      或者阅读这里的讨论: https://stackoverflow.com/a/379622/2671523

      【讨论】:

        猜你喜欢
        • 2013-11-23
        • 2013-09-19
        • 1970-01-01
        • 1970-01-01
        • 2017-05-29
        • 2015-04-04
        • 1970-01-01
        • 2018-02-26
        • 1970-01-01
        相关资源
        最近更新 更多