2
私のプロジェクトでは、選択ボックス値の変更時にデータベース内のオブジェクトを更新する必要がある私のテーブルに選択ボックスがあります。このようにして、選択した選択オプションの値を取得しました。問題は、データベース内の値が 、私のコントローラsymfony update with javascript(Ajax)
public function editAction(Request $request, Client $client)
{
$deleteForm = $this->createDeleteForm($client);
$editForm = $this->createForm('AppBundle\Form\ClientType', $client);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$status = $request->request->get('status');
$client->setStatus($status);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('client_index');
}
return $this->render('client/edit.html.twig', array(
'client' => $client,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
私のJSで
function update(id, status){
var statusValue = {'status':status};
var path = Routing.generate('client_edit',{'id': id});
$.ajax({
type: "POST",
url: path,
data: statusValue
});
}
を変更されないで、更新すべきIDだからここ
<td>
<select id="status" name="status" onchange="update({{ client.id }}, this.value)">
<option {% if client.status is empty %}
selected
{% endif %}>Status</option>
<option {% if client.status == 'Envoyer') %}
selected
{% endif %}
value="Envoyer">Envoyer</option>
<option {% if client.status == 'Annuler') %}
selected
{% endif %}
value="Annuler">Annuler</option>
<option {% if client.status == 'Rejetter') %}
selected
{% endif %}
value="Rejeter">Rejeter</option>
</select>
クライアントインデックスに私のテーブルには、私はidと私のデータベースの更新にそれを行うことができますが、何も私のデータベースで更新されていない選択セレクトオプションの値は、取得するには、ありがとう!フォームが送信されることはありませんので
- > persist($ client); - > flush()? – Generwp
ありがとうございますが、何も変わりません! – Mathias
あなたのコードはisValidチェックを渡しますか?私。あなたのフォームにはフォーム/エンティティの検証が失敗する可能性のある他のフィールドが含まれていますか(ajaxリクエストに何も渡していないので)? – ejuhjav