2012-04-09 15 views
0

ドロップされた項目(jqueryui draggables/droppables/sortablesを使用)から取得した要素IDから取得したデータを、ここでデータと共にフォーム(電子メールで送信)を介して送信する必要があります。フォーム送信時に要素IDを送信する

function getSku() { 
var myIds = new array(); 
     $("#collection li").each(function(index, element){ 
       alert($(this).attr('id')); 
      myIds.push(element.id); 

      }); 

と、フォームは次のようになります:(それは右、まだどちらか動作するかどうかわからない)

 function submitForm() { 
$.ajax({type:'POST', 
     url: 'send_tile.php', 
     data:$('#tiles_collected').serialize(), 
     success: function(response) { 
    $('#tiles_collected').find('.form_result').html(response); 
}}); 

return false; 
    } 

IDを取得するための機能がこれです

 <form id="tiles_collected" name='tiles_collected' method="post" onsubmit="return submitForm();"> 
     Email:<input name='email' id='email' type='text'/><br /> 
     Name:<input name='name' id='name' type='text' /><br /> 
     Zip code: <input name='zip' id='zip' type='text' /><br /> 
     <input type='hidden' id='sku' /> 
     <input type="submit" name="submit" value="Email collection to yourself and us" /><br/> 
     <div class="form_result"></div> 
     </form> 

誰でも私に助けを与えることができますか?

+0

そして、あなたはsend_tile.phpであなたの第二の例ではmyIds配列 –

答えて

0

サーバーに送信されるデータにIDを追加するだけで、拡張を使用することも、Ajax関数で追加することもできます。

拡張:

function submitForm() { 
    var MyData = $('#tiles_collected').serialize(); 
    $.extend(MyData, {IDs: myIds}); //myIds will have to be accessable, right now it's a local variable in your getSku() function 

    $.ajax({type:'POST', 
     url: 'send_tile.php', 
     data: MyData, 
     success: function(response) { 
      $('#tiles_collected').find('.form_result').html(response); 
     } 
    }); 
    return false; 
} 

か、単にそれらを直接追加します。

function getSku() { 
    var myIds = new array(); 
    $("#collection li").each(function(index, element){ 
     myIds.push(element.id); 
    }); 
    return myIds; 
} 

var IDs = getSku(); 

$.ajax({type:'POST', 
    url: 'send_tile.php', 
    data: {data : $('#tiles_collected').serialize(), ids : IDs}, 
    success: function(response) { 
     $('#tiles_collected').find('.form_result').html(response); 
    } 
}); 
+0

を使用しているが、私はちょうどとしてそれを参照してください'ids'を指定すると実際にその値を電子メールに出力します。 – MirlyMir

+0

PHPでは、ajax関数で送信される値は、$ _POST ['ids ']などで利用できます。print_r($ _ POST)を実行して、保持する内容や変数のダンプなどを確認してください。 – adeneo

+0

$(' tiles_collected ' ).serialize()はそのメソッドを使用してもはや動作していないようで、私はまだ 'ids'のいずれも見ていません。 – MirlyMir

関連する問題