我有页面,用户可以添加日期范围、至和价格。默认情况下有三个,但用户可以使用添加日期范围按钮按钮添加更多范围。我的问题是,在我获得$_POST
值时添加了一些额外的日期范围后,它没有显示附加的 html 元素的 post 值。
javascript部分
var n = 0;
$(document).ready(function () {
$("#btn2").click(function () {
$("#add_drange").append(" <p><input type='text' name='from" + n + "' class='datepicker' placeholder='From' /> <input type='text' name='to" + n + "' class='datepicker' placeholder='To' /> <input type='text' name='price" + n + "'id='price' placeholder='Price in USD' /></p>");
n = n + $("#add_drange").length;
//c = c + n;
//alert(n);
if (n == 25) {
alert('You can only add 25 Date Ranges');
event.preventDefault();
$("#btn2").hide();
}
$(".datepicker").datepicker({
dateFormat: 'yy-mm-dd'
}).val();
});
});
HTML
<div id="add_drange">
<br>
<h1>Add Price for Date Ranges</h1>
<br>
<form action="" method="post" name="add_price">
<p>
<input type="text" name="from_f_1" class="datepicker" placeholder="From" />
<input type="text" name="to_f_1" class="datepicker" placeholder="To" />
<input type="text" name="price_f_1" id="price" placeholder="Price in USD" />
</p>
<p>
<input type="text" name="from_f_2" class="datepicker" placeholder="From" />
<input type="text" name="to_f_2" class="datepicker" placeholder="To" />
<input type="text" name="price_f_2" id="price" placeholder="Price in USD" />
</p>
<p>
<input type="text" name="from_f_3" class="datepicker" placeholder="From" />
<input type="text" name="to_f_3" class="datepicker" placeholder="To" />
<input type="text" name="price_f_3" id="price" placeholder="Price in USD" />
</p>
</div>
<br>
<input type="button" id="btn2" name="add_more" value="AddMore Data Ranges" />
<br>
<br>
<br>
<br>
<h1>Alter you Base Price for Each Day of the Week</h1>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quam velit, vulputate eu pharetra nec, mattis ac neque. Duis vulputate commodo lectus, ac blandit elit tincidunt id. Sed rhoncus, tortor sed eleifend tristique, tortor mauris molestie elit, et lacinia ipsum quam nec dui.</p>
<br>
<input type="text" id="" name="sunday" placeholder="Sunday" size="8" />
<input type="text" id="" name="monday" placeholder="Monday" size="8" />
<input type="text" id="" name="tuesday" placeholder="Tuesday" size="8" />
<input type="text" id="" name="wednesday" placeholder="Wednesday" size="8" />
<input type="text" name="Thursday" id="" placeholder="Thursday" size="8" />
<input type="text" name="Friday" id="" placeholder="Friday" size="8" />
<input type="text" name="Saturday" id="" placeholder="Saturday" size="8" />
<br>
<br>
<input type="submit" id="save" name="save_all" value="save" style="float: right;" />
</form>
PHP
///dynamic created text feild part
$dynamic_feild;
for($n=0;$n<25;$n++)
{
$dynamic_feild[$n][0]=$_POST['from'."$n"];
$dynamic_feild[$n][1]=$_POST['to'."$n"];
$dynamic_feild[$n][2]=$_POST['price'."$n"];
}
var_dump($dynamic_feild);