現在、Twigでテーブルを正しく表示させたいのですが、
私の思った通りに表示されません。
正しくは下記のように表示させたいです。
商品名|個数|価格 みかん|3 |200 りんご|1 |500
ですが、現状はこのようになっております。(入力確認フォーム)
入力フォーム→入力確認フォームへと遷移させて入力確認フォームでテーブルを表示させている状態です。
入力フォームから情報を入力確認フォームへと送信し、入力確認フォームで
「商品名」
「個数」
「価格」
の情報を配列で受け取っています。
入力フォームでは静的に5行のフォームを作成しており
入力確認フォームで入力された行数分のみ表示させたいです。
上記の用に、正しく表示させるために
辺りをつけてコードを修正したりしましたがうまくいきません。
どのあたりのコードが間違っているのでしょうか?
・入力フォーム(HTML(TWig)) 静的に5このフォームを用意
html
1 <table class="table table-bordered"> 2 <form action="voucher_confirm.php" method="post"> 3 <thead> 4 <tr> 5 <th>商品名</th> 6 <th>個数</th> 7 <th>価格</th> 8 </tr> 9 </thead> 10 11 12 13 <tbody> 14 <tr> 15 <font color="RED"> {{ productName_error }} </font> 16 <th><input type="text" name="productName[]" class="form-control" value="{{ productName }}"></th> 17 <font color="RED"> {{ number_error }} </font> 18 <td><input type="text" name="number[]" class="form-control" value="{{ number }}"></td> 19 <font color="RED"> {{ price_error }} </font> 20 <td><input type="text" name="price[]" class="form-control" value="{{ price }}"></td> 21 </tr> 22 <tr> 23 <th><input name="productName[]" class="form-control" type="text"></th> 24 <td><input name="number[]" class="form-control" type="text"></td> 25 <td><input name="price[]" class="form-control" type="text"></td> 26 </tr> 27 <tr> 28 <th><input name="productName[]" class="form-control" type="text"></th> 29 <td><input name="number[]" class="form-control" type="text"></td> 30 <td><input name="price[]" class="form-control" type="text"></td> 31 </tr> 32 <tr> 33 <th><input name="productName[]" class="form-control" type="text"></th> 34 <td><input name="number[]" class="form-control" type="text"></td> 35 <td><input name="price[]" class="form-control" type="text"></td> 36 </tr> 37 <tr> 38 <th><input name="productName[]" class="form-control" type="text"></th> 39 <td><input name="number[]" class="form-control" type="text"></td> 40 <td><input name="price[]" class="form-control" type="text"></td> 41 </tr> 42 </tbody> 43 </table>
・入力確認フォーム(PHP) 一部のコードのみ
PHP
1$voucher = [ 2 filter_input(INPUT_POST, 'productName', FILTER_DEFAULT,FILTER_REQUIRE_ARRAY), 3 filter_input(INPUT_POST, 'number', FILTER_DEFAULT,FILTER_REQUIRE_ARRAY), 4 filter_input(INPUT_POST, 'price', FILTER_DEFAULT,FILTER_REQUIRE_ARRAY) 5];
・入力確認フォーム(HTML(Twig))
html
1 <table class="table table-bordered"> 2 <thead> 3 <tr> 4 <th>商品名</th> 5 <th>個数</th> 6 <th>価格</th> 7 </tr> 8 </thead> 9 <tbody> 10 11 {% for value in voucher_value %} 12 <tr> 13 <td> 14 <p class="form-control-static">{{ value.0 }} </p> 15 </td> 16 17 <td> 18 <p class="form-control-static">{{ value.1 }}</p> 19 </td> 20 21 <td> 22 <p class="form-control-static"> {{ value.2 }} </p> 23 </td> 24 </tr> 25 {% endfor %} 26 27 </tbody> 28 </table>
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。