gpt4 book ai didi

php - 如何在具有多个 foreach 的表单中仅显示 1 个提交按钮

转载 作者:行者123 更新时间:2023-11-28 00:48:37 25 4
gpt4 key购买 nike

目前我有一个表单并使用 foreach 调用一些数据,如下所示:

@foreach($db as $intentName => $questionAnswer)

<div class="form-group edit-response-container">
<label data-toggle="collapse" data-target="#collapse-{{$number}}" aria-expanded="false" aria-controls="collapse-{{$number}}"> {{$intentName}} <i class="fa fa-chevron-down"></i></label>
<div class="collapse" id="collapse-{{$number}}">
<div class="well">

<form action="{{action('AltHr\Chatbot\ChatbotController@savedmb', [$companyID, $entityType])}}" method="post">
{{csrf_field()}}
<div class="col-md-12 btn-toolbar">
<button type="button" class="btn alt-btn alt-btn-green pull-right add-new">Add Answer</button>
<button type="submit" class="btn alt-btn alt-btn-green pull-right">Save</button>
</div>

@foreach($questionAnswer['q1'] as $question => $questionID)
<table class="question">
<tr>
<td class="labels"><p>User:</p></td>
<td><p>&nbsp;{{ str_replace("<title>", "$q", $question) }}</p></td>
<input type="hidden" name="question[]" value="{{ str_replace("<title>", "$q", $question) }}">
</tr>
</table>
@endforeach

@foreach($questionAnswer['q2'] as $question => $questionID)
<table class="question">
<tr>
<td class="labels"><p>User:</p></td>
<td><p>&nbsp;{{ str_replace("<title>", "$q", $question) }}</p></td>
<input type="hidden" name="question[]" value="{{ str_replace("<title>", "$q", $question) }}">
</tr>
</table>
@endforeach

@foreach($questionAnswer['q3'] as $question => $questionID)
<table class="question">
<tr>
<td class="labels"><p>User:</p></td>
<td><p>&nbsp;{{ str_replace("<title>", "$q", $question) }}</p></td>
<input type="hidden" name="question[]" value="{{ str_replace("<title>", "$q", $question) }}">
</tr>
</table>
@endforeach

@foreach($questionAnswer['intent'] as $intent => $intent)
<input type="hidden" name="intent" value="{{$intent}}">
@endforeach

<input type="hidden" name="entityValue" value="{{$q}}" readonly/>

<br><br>

<div class="new-field">
<table class="response">
<tr>
<td class="labels"><p>Answer:</p></td>
<td><input type="text" name="newAnswer[]" value=""></td>
</tr>
</table>
</div>
</form>
</div>
</div>
</div>

<?php
$number++;
?>

@endforeach

所以功能一切正常,但我有一个问题,正如您从下图中看到的那样,表格是相同的,但如果我没记错的话,目前按钮在每个 foreach 上显示给我,但我只想提交一个和一个添加按钮,而不是所有的 foreach。我该怎么做?

enter image description here

我的 Controller 如下:

public function savedmb(Request $request, $companyID, $entityType)
{
$a = count($request->question);
for ($p=0; $p < $a; $p++) {

$nq = new DiraQuestion;
$nq->intent = strtolower($request->intent);
$nq->eType = $entityType;
$nq->eVal = strtolower($request->entityValue);
//$nq->synonym = strtolower($request->syn);
$nq->queries = $request->question[$p];
$nq->company_id = $companyID;
$nq->save();

}


$x = count($request->newAnswer);
for ($i=0; $i < $x; $i++) {

$nr = new DiraResponses;
$nr->intent = strtolower($request->intent);
$nr->eType = $entityType;
$nr->eVal = strtolower($request->entityValue);
$nr->reply = strtolower($request->newAnswer[$i]);
$nr->company_id = $companyID;
$nr->save();

}

return back();
}

还有我的路线:

Route::post('savedmb/{companyID}/{entityType}','Chatbot\ChatbotController@savedmb');

最佳答案

将按钮放在 循环之外:

<div class="form-group edit-response-container">
<label data-toggle="collapse" data-target="#collapse-{{$number}}" aria-expanded="false" aria-controls="collapse-{{$number}}"> {{$intentName}} <i class="fa fa-chevron-down"></i></label>
<div class="collapse" id="collapse-{{$number}}">
<div class="well">

<form action="{{action('AltHr\Chatbot\ChatbotController@savedmb', [$companyID, $entityType])}}" method="post">
{{csrf_field()}}
<div class="col-md-12 btn-toolbar">
<button type="button" class="btn alt-btn alt-btn-green pull-right add-new">Add Answer</button>
<button type="submit" class="btn alt-btn alt-btn-green pull-right">Save</button>
</div>
@foreach($db as $intentName => $questionAnswer)
@foreach($questionAnswer['q1'] as $question => $questionID)
<table class="question">
<tr>
<td class="labels"><p>User:</p></td>
<td><p>&nbsp;{{ str_replace("<title>", "$q", $question) }}</p></td>
<input type="hidden" name="question[]" value="{{ str_replace("<title>", "$q", $question) }}">
</tr>
</table>
@endforeach

@foreach($questionAnswer['q2'] as $question => $questionID)
<table class="question">
<tr>
<td class="labels"><p>User:</p></td>
<td><p>&nbsp;{{ str_replace("<title>", "$q", $question) }}</p></td>
<input type="hidden" name="question[]" value="{{ str_replace("<title>", "$q", $question) }}">
</tr>
</table>
@endforeach

@foreach($questionAnswer['q3'] as $question => $questionID)
<table class="question">
<tr>
<td class="labels"><p>User:</p></td>
<td><p>&nbsp;{{ str_replace("<title>", "$q", $question) }}</p></td>
<input type="hidden" name="question[]" value="{{ str_replace("<title>", "$q", $question) }}">
</tr>
</table>
@endforeach

@foreach($questionAnswer['intent'] as $intent => $intent)
<input type="hidden" name="intent" value="{{$intent}}">
@endforeach

<input type="hidden" name="entityValue" value="{{$q}}" readonly/>

<br><br>

<div class="new-field">
<table class="response">
<tr>
<td class="labels"><p>Answer:</p></td>
<td><input type="text" name="newAnswer[]" value=""></td>
</tr>
</table>
</div>
<?php
$number++;
?>

@endforeach
</form>
</div>

关于php - 如何在具有多个 foreach 的表单中仅显示 1 个提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48780702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com