我创建了一个用户过滤器表单,结果将其显示为复选框,但我想让用户选中以向其发送SMS。 我的问题在于检查值的恢复步骤
感谢您的帮助。
我创建了一个发送SMS的功能,但是我必须将复选框中选中的用户的电话号码作为参数传递给他。
树枝文件:
<div class="box-body">
<form method="POST" action="{{ path('ce_utilisateur_send_sms') }}" id="lbad_form_sms" name="users">
<div class="table-responsive">
<table id="tableuser"
class="table table-bordered table-striped table-hover dt-responsive display nowrap"
cellspacing="0">
<thead>
<tr>
<th>
Client
</th>
<th>Téléphone</th>
<th>Nombre de commandes</th>
<th>Date de la dernière commande</th>
<th class="nosort">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="checkbox">
<label>
<input name="allusers" type="checkbox"
value="users">
Tous les clients
</label>
</div>
</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
{% if listUsers is not empty %}
{% for usr in listUsers %}
<tr>
<td>
<div class="checkbox">
<label>
<input name="usr_[{{usr.id}}]" type="checkbox"
value="{{ usr.telephone }}">
<span> {{ usr.username }}</span>
</label>
</div>
</td>
<td>{{ usr.telephone }}</td>
<td>{{ usr.commandes.count }}</td>
{% if usr.commandes is empty %}
<td>-</td>
{% else %}
<td>{{ usr.getLastCommande.dateCommande|date('d/m/Y à H:i') }}</td>
{% endif %}
<td>
<a class="btn btn-xs bg-navy" name="Voir détails"
data-toggle="modal" data-target="#{{ usr.id }}modal">
<i class="fa fa-eye"></i>
</a>
</td>
</tr>
{% endfor %}
{% endif %}
</tbody>
<tfoot>
<tr>
<th>Client</th>
<th>Téléphone</th>
<th>Nombre de commandes</th>
<th>Date de la dernière commande</th>
<th class="nosort">Action</th>
</tr>
</tfoot>
</table>
</div>
</div>
<div class="box-footer">
<a href="{{ path('ce_utilisateur_send_sms') }}" class="btn btn-primary lbad_btngc">Envoyer un sms</a>
</div>
</form>
我的函数sendSms
public function sendSmsAction(Request $request, SmsProvider
$provider)
{
$users = $request->get('allusers')->getData();
var_dump($users);
die();//returns null, I do not know how to get that in a twig
form to pass it in the second form (smsFormType)
$form = $this->createForm(smsFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$message = $form->get('message')->getData();
$objet = $form->get('objet')->getData();
$provider->sendMessage($message, $object, $phonenumbers);
}
}