2012-03-23 78 views
0

我正在处理配方表单,其中有许多字段要求配方成分。 例如我的代码是一些这样的事循环遍历所有特定的表单字段

  <legend><span>Recipe Ingredients</span></legend> 
       <label for="recipe_ing" title="Ingredients Name" class="required">Ingredient:<span>*</span></label> 
       <input name="recipe_ingr" id="recipe_ingr" size="10" /> &nbsp; 
       Quantity: <input id="recipe_qty" name="recipe_qty" size="5" /> &nbsp; 
       unit: <input id="recipe_unit" name="recipe_unit" size="5" /> &nbsp; 
       Notes: <input type="text" id="recipe_notes" name="recipe_notes" size="15" />&nbsp; <br /><br /> 


       <label for="recipe_ing" title="Ingredients Name" class="required">Ingredient2:<span>*</span></label> 
       <input name="recipe_ingr2" id="recipe_ingr" size="10" /> &nbsp; 
       Quantity: <input id="recipe_qty" name="recipe_qty2" size="5" /> &nbsp; 
       unit: <input id="recipe_unit" name="recipe_unit2" size="5" /> &nbsp; 
       Notes: <input type="text" id="recipe_notes" name="recipe_notes2" size="15" />&nbsp; <br /><br /> 

其上升到15的成分,数量,单位,并指出

表单数据处理和控制由formcheck.php

现在问题或我的问题是,formcheck.php中可能的选项/函数是什么,这样,而不是定义15次if(isset($ _ POST []))我运行一个循环直到它获得所有相关数据的成分,数量,单位和票据

我希望我能让自己清楚

回答

0

如果您在不同的表单字段中填写数字,该怎么办? 所以制作15个“recipe_ingr”字段。在Perl中,你会得到1个变量,其中包含所有的值。

或从1到15做一个for循环?

+0

我可以进行任何所需的更改,我可以让它们全部为recipe_ingr。因为我不太了解php,那么循环所有值的正确循环函数是什么? – user10105 2012-03-23 14:37:59

+0

我不知道PHP(无论),但也许这可以帮助你: http://snippets.dzone.com/posts/show/3699 – 2012-03-26 07:25:35