0

リスト内のすべてのオブジェクトに隠しフィールドを追加するフォームがあり、これは foreach を使用して次のページで取得されます。それはすべて正常に動作します。

私の質問は、そのリストに別の変数を追加する必要があるということです。これまでのところ、これは日付/時刻です。同じ foreach で別の値を取得するにはどうすればよいですか?

ありがとう

フォーム:

 <form action="test.php" id="calendarform" method="post">
    <input type="submit" value="Export Calendar"/>
 </form>    

jQuery:

    $('#calendarform').submit(function(e) {
            var form = $(this);
            var listItems = $('.listItem'); 
            listItems.each(function(index){   //For each event do this:
                var listItem = $(this);
                $("<input type='hidden'/>").val(listItem.text()).appendTo(form).attr('name', 'listItem[' + index + ']');
                });

応答ページ:

foreach($_POST['listItem'] as $key => $value){

      $eventDate = trim($value);

 }

そして最後に、どのように機能させたいですか:

 foreach($_POST['listItem'] as $key => $value){

      $eventDate = trim($value);
      $eventTitle = trim($value2);


 }
4

1 に答える 1

0

listItem が似ている場合

<input name="listItem[0][]">date <input name="listItem[0][]">title 
<input name="listItem[1][]">date <input name="listItem[1][]">title 

あなたができる:

foreach($_POST['listItem'] as $key => $values){
  list($eventDate, $eventTitle) = $values;
}
于 2012-05-11T09:25:54.813 に答える