将动态表单数据输出到PHP数组

时间:2012-03-10 19:10:43

标签: php jquery post

我正在尝试将信息从动态表单传递到我的数据库。我正在使用jquery为表单中的数量和成分添加其他字段。然后,我希望能够将这些详细信息提交到我的数据库。 jQuery工作正常,但我不确定如何使用PHP来做到这一点。我正在使用以下代码:

HTML

<form id="htmlForm" method="post" action="includes/add-recipe.php" class="form-inline"> 
        <input type="text" name="recipeName" class="input-large" placeholder="Recipe Title"><br /><br />
        <div id="input1" style="margin-bottom:4px;" class="clonedInput">
            Ingredient:<br /> 
            <select type="text" name="entry[][$ing]"/>
                <option value="Eggs">Eggs</option>
                <option value="Flour">Flour</option>
                <option value="Wheat">Wheat</option>
            </select><input type="text" name="entry[][$qty]" class="input-small" placeholder="Quantity">
        </div><br />
        <div>
            <input type="button" id="btnAdd" class="input-small" value="add another ingredient" />
            <input type="button" id="btnDel" class="input-small" value="remove name" />
        </div><br />
        <button type="submit" class="btn">Add Recipe</button>
    </form>

的Javascript

<script type="text/javascript">
        $(document).ready(function() {
            $('#btnAdd').click(function() {
                var num     = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
                var newNum  = new Number(num + 1);      // the numeric ID of the new input field being added
                var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);

                newElem.children(':first').attr('id', 'entry' + newNum).attr('entry', 'entry' + newNum);
                $('#input' + num).after(newElem);
                $('#btnDel').attr('disabled','');
                if (newNum == 5)
                    $('#btnAdd').attr('disabled','disabled');
            });

            $('#btnDel').click(function() {
                var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
                $('#input' + num).remove();     // remove the last element

                $('#btnAdd').attr('disabled','');
                if (num-1 == 1)
                    $('#btnDel').attr('disabled','disabled');
            });

            $('#btnDel').attr('disabled','disabled');
        });
    </script>

PHP

<?php


    foreach ($_POST["entry"] AS $aQtyIng)
    {
        list($ing, $qty) = $aQtyIng;
        echo $aQtyIng;
    }


?>

0 个答案:

没有答案