How to deal with dynamic number of form input using PHP?
<p>Hi i have a form where user can select start date and end date of a leave. For example when the no of days is 3, there will be 3 row of date generated. Each date,day and period (am/pm) will be stored in the hidden field. So 3 days will generate a hidden field with name date_1, day_1, period_1, date_2, day_2, period_2, date_3, day_3, period_3.</p>

<p>The question is how to deal with this dynamic number of form input? I need to pass the value to the controller and then to model to store into database. This is the main problem since form input is number is dynamic and we need to pass it to the controller function.</p>

<p>Can someone show me the correct way of dealing with this problem? A link of tutorial will be helpful thanks :)</p>

<p>This is the code that is use to generate the list of date as in the picture below</p>

<pre><code>function test(){
            var count = 0;
            var date1 = $('#alternatestartdate').val();
            var date2 = $('#alternateenddate').val();
            var startDate = new Date(date1);
            var endDate = new Date(date2);
            var Weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
            while (startDate&lt;=endDate)
            {
            var weekDay = startDate.getDay();
            if (weekDay &lt; 6 &amp;&amp; weekDay &gt; 0) {
            var month = startDate.getMonth()+1;
            if( month &lt;= 9 ) { month = "0"+month; }
            var day = startDate.getDate();
            var datearr = new Array();
            if( day &lt;= 9 ) { day = "0"+day; }
            count++;
            var datelist = day+"-"+month+"-"+startDate.getFullYear();
            $('#pa').append(day+"-"+month+"-"+startDate.getFullYear() + " ("+Weekday[weekDay]+") &lt;input type='hidden' id='' name='date_"+count+"' value='"+datelist+"' /&gt;&lt;input type='hidden' id='' name='day_"+count+"' value='"+Weekday[weekDay]+"' /&gt;&lt;input type='radio' name='period_"+count+"' value='1' checked/&gt;Full&lt;input type='radio' name='period_"+count+"' value='2'/&gt;Half (AM)&lt;input type='radio' name='period_"+count+"' value='3'/&gt;Half (PM)&lt;br /&gt;");

            }
            startDate.setDate(startDate.getDate()+1)
            }
            $('#pa').append("&lt;input type='hidden' id='' name='countval' value='"+count+"' /&gt;");
        }
</code></pre>

<p><img src="http://i.stack.imgur.com/nd8a8.jpg" alt="alt text"></p>

<p>If insert correctly, the data the in database will look like this:</p>

<p><img src="http://i.stack.imgur.com/qZdNH.jpg" alt="alt text"></p>
