0

Redbean を使用してサイトを作成しており、現在、ユーザー向けにレシピのアップロード機能を実装しています。

「レシピのアップロード」フォームでは、javascript を使用して 4 つの入力フィールド (量、測定、成分、メモ) を動的に追加しました。ただし、ユーザーが送信をクリックすると、redbean を使用してこれらを保存する方法がわかりません。誰でも何か提案できますか?追加された各フィールドをループしてデータベースに保存するには、ループを使用する必要がありますか?

私が使用しているコードは次のとおりです。

var count = 0;

$(function(addfield){
    $('p#add_field').click(function(){  
        count += 1;  
        $('#container').append(   
            '<strong>Ingredient ' + count + '</strong><br />'    
                + '`<`input id="field_' + count + 'name="amount" type="text" placeholder="Amount" `/>`'     +  
                 '<input id="field_' + count + 'name="measurement" type="text" placeholder="Measurement" `/>`'+   
                 '<input id="field_' + count + 'name="ingredient" type="text" placeholder="Ingredient" `/>`' +  
                 '<input id="field_' + count + 'name="notes" type="text" placeholder="Notes" `/>`' +   
        );  
    });  
});

そして、これは関数を呼び出すためのリンクです:

<p id="add_field"><a href="#addfield"><span>&raquo; Click to add ingredient</span></a></p>
4

1 に答える 1

0

コードをループに入れるだけです。

for($a=0;$a<4;$a++){
    $recipe=R::dispense('recipe');
    $recipe->import($_POST['recipe_'.$a]);//You need to configure this portion
    //OR
    $recipe->title=$_POST['recipe'][$a]['title'];
    R::store($recipe);
}
于 2012-12-20T17:18:39.870 に答える