我有一个表格,我要求以前的地址。我正在使用数组来收集地址。设置为仅显示一个地址,然后他们可以单击一个按钮,将显示另一组地址字段,以便他们可以输入任意数量的地址。他们的想法是让他们进入他们生活的最后7年。我得到的问题是,当帖子通过我只获得第一组地址。我不确定我之前做过什么是错的。
这是第一组地址字段html
=Fields!Requests.Value/100
如果有人点击添加另一个地址,则会在上面的html之后附加。
<div class='row address1'>
<div class='addresstxt'>
<input type='text' class='addresstxt' name='address[1][txt]' id='address1txt' onchange="capwords(this.id, this.value)" />
</div>
<div class='addresscitytxt'>
<input type='text' class='addresscitytxt' name='address[1][city]' id='address1city' onchange="capwords(this.id, this.value)" />
</div>
<div class='addressstatetxt'>
<select class='addressstatetxt' name='address[1][state]' id='address1state'>
<option disabled selected value='select'>Select</option>
Taken out to shorten
</select>
</div>
<div class='addresscountytxt'>
<input type='text' class='addresscountytxt' name='address[1][county]' id='address1county' onchange="capwords(this.id, this.value)" />
</div>
<div class='addressziptxt'>
<input type='text' class='addressziptxt' name='address[1][zip]' id='address1zip' />
</div>
<div class='addressfromtxt'>
<input type='text' class='addressfromtxt datepicker_recurring_start' name='address[1][from]' id='address1from' />
</div>
<div class='addresstilltxt'>
<input type='text' class='addresstilltxt datepicker_recurring_start' name='address[1][till]' id='address1till' value='' />
</div>
</div>
当我为地址执行$ _POST的var_dump时,我只输入第一个。
<div class="row address2">
<div class="addresstxt">
<input type="text" class="addresstxt" name="address[2][txt]" id="address2txt" onchange="capwords(this.id, this.value)">
</div>
<div class="addresscitytxt">
<input type="text" class="addresscitytxt" name="address[2][city]" id="address2city" onchange="capwords(this.id, this.value)">
</div>
<div class="addressstatetxt">
<select class="addressstatetxt" name="address[2][state]" id="address2state">
</select>
</div>
<div class="addresscountytxt">
<input type="text" class="addresscountytxt" name="address[2][county]" id="address2county" onchange="capwords(this.id, this.value)">
</div>
<div class="addressziptxt">
<input type="text" class="addressziptxt" name="address[2][zip]" id="address2zip">
</div>
<div class="addressfromtxt">
<input type="text" class="addressfromtxt datepicker_recurring_start hasDatepicker" name="address[2][from]" id="address2from">
</div>
<div class="addresstilltxt">
<input type="text" class="addresstilltxt datepicker_recurring_start hasDatepicker" name="address[2][till]" id="address2till" value="">
</div>
<div class="row address2">
<div class="addresstxt">
<input type="text" class="addresstxt" name="address[2][txt]" id="address2txt" onchange="capwords(this.id, this.value)">
</div>
<div class="addresscitytxt">
<input type="text" class="addresscitytxt" name="address[2][city]" id="address2city" onchange="capwords(this.id, this.value)">
</div>
<div class="addressstatetxt">
<select class="addressstatetxt" name="address[2][state]" id="address2state">
</select>
</div>
<div class="addresscountytxt">
<input type="text" class="addresscountytxt" name="address[2][county]" id="address2county" onchange="capwords(this.id, this.value)">
</div>
<div class="addressziptxt">
<input type="text" class="addressziptxt" name="address[2][zip]" id="address2zip">
</div>
<div class="addressfromtxt">
<input type="text" class="addressfromtxt datepicker_recurring_start hasDatepicker" name="address[2][from]" id="address2from">
</div>
<div class="addresstilltxt">
<input type="text" class="addresstilltxt datepicker_recurring_start hasDatepicker" name="address[2][till]" id="address2till" value="">
</div>
</div>
</div>
我能想到可能是什么问题的唯一原因是因为我在点击添加地址按钮加载页面后添加了集合但是我很确定我之前已经添加了输入字段这不是问题。希望有人可以跳进去,也许让我知道我做错了什么。
由于
答案 0 :(得分:0)
这是您提供的工作版本,不确定您的代码之间有什么不同。我的假设(虽然你的评论蒙上阴影)是你的JS事件在<form>
之外附加了额外的输入。如果没有,也许有这个工作代码可以让你弄清楚你的错误。当我在PHP后端(submit.php)上使用var_dump($_POST);
时,我看到所有三个地址数组。
<button class='new-addresses'>Click</button>
<form action='submit.php' method='post'>
<div class='row address1'>
<div class='addresstxt'>
<input type='text' class='addresstxt' name='address[1][txt]' id='address1txt' onchange="capwords(this.id, this.value)"/>
</div>
<div class='addresscitytxt'>
<input type='text' class='addresscitytxt' name='address[1][city]' id='address1city' onchange="capwords(this.id, this.value)"/>
</div>
<div class='addressstatetxt'>
<select class='addressstatetxt' name='address[1][state]' id='address1state'>
<option disabled selected value='select'>Select</option>
</select>
</div>
<div class='addresscountytxt'>
<input type='text' class='addresscountytxt' name='address[1][county]' id='address1county' onchange="capwords(this.id, this.value)"/>
</div>
<div class='addressziptxt'>
<input type='text' class='addressziptxt' name='address[1][zip]' id='address1zip'/>
</div>
<div class='addressfromtxt'>
<input type='text' class='addressfromtxt datepicker_recurring_start' name='address[1][from]' id='address1from'/>
</div>
<div class='addresstilltxt'>
<input type='text' class='addresstilltxt datepicker_recurring_start' name='address[1][till]' id='address1till' value=''/>
</div>
</div>
<input type='submit' value='Submit'>
</form>
<script src='https://code.jquery.com/jquery-1.12.0.min.js'></script>
<script>
$(".new-addresses").on('click', function(){
$("form input[type=submit]").before(
'<div class="row address2"><div class="addresstxt"><input type="text" class="addresstxt" name="address[2][txt]" id="address2txt" onchange="capwords(this.id, this.value)"></div><div class="addresscitytxt"><input type="text" class="addresscitytxt" name="address[2][city]" id="address2city" onchange="capwords(this.id, this.value)"></div><div class="addressstatetxt"><select class="addressstatetxt" name="address[2][state]" id="address2state"></select></div><div class="addresscountytxt"><input type="text" class="addresscountytxt" name="address[2][county]" id="address2county" onchange="capwords(this.id, this.value)"></div><div class="addressziptxt"><input type="text" class="addressziptxt" name="address[2][zip]" id="address2zip"></div><div class="addressfromtxt"><input type="text" class="addressfromtxt datepicker_recurring_start hasDatepicker" name="address[2][from]" id="address2from"></div><div class="addresstilltxt"><input type="text" class="addresstilltxt datepicker_recurring_start hasDatepicker" name="address[2][till]" id="address2till" value=""></div><div class="row address3"><div class="addresstxt"><input type="text" class="addresstxt" name="address[3][txt]" id="address3txt" onchange="capwords(this.id, this.value)"></div><div class="addresscitytxt"><input type="text" class="addresscitytxt" name="address[3][city]" id="address3city" onchange="capwords(this.id, this.value)"></div><div class="addressstatetxt"><select class="addressstatetxt" name="address[3][state]" id="address3state"></select></div><div class="addresscountytxt"><input type="text" class="addresscountytxt" name="address[3][county]" id="address3county" onchange="capwords(this.id, this.value)"></div><div class="addressziptxt"><input type="text" class="addressziptxt" name="address[3][zip]" id="address3zip"></div><div class="addressfromtxt"><input type="text" class="addressfromtxt datepicker_recurring_start hasDatepicker" name="address[3][from]" id="address3from"></div><div class="addresstilltxt"><input type="text" class="addresstilltxt datepicker_recurring_start hasDatepicker" name="address[3][till]" id="address3till" value=""></div></div>'
);
});
</script>
编辑:这是PHP输出(我没有为选择添加选项,因此它们不会显示在PHP页面上):
array (size=1)
'address' =>
array (size=3)
1 =>
array (size=6)
'txt' => string 'test' (length=4)
'city' => string 'test' (length=4)
'county' => string 'test' (length=4)
'zip' => string 'test' (length=4)
'from' => string 'test' (length=4)
'till' => string 'test' (length=4)
2 =>
array (size=6)
'txt' => string 'test2' (length=5)
'city' => string 'test2' (length=5)
'county' => string 'test2' (length=5)
'zip' => string 'test2' (length=5)
'from' => string 'test2' (length=5)
'till' => string 'test2' (length=5)
3 =>
array (size=6)
'txt' => string 'test3' (length=5)
'city' => string 'test3' (length=5)
'county' => string 'test3' (length=5)
'zip' => string 'test3' (length=5)
'from' => string 'test3' (length=5)
'till' => string 'test3' (length=5)