2012-03-23 77 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