PHP代码不允许通过我的表单发送多个输入值 [英] PHP code isn't allowing multiple input values to send through my form
问题描述
<?php
{
foreach($ results ['tags'] as $ part){
if($ part ['category'] ==Part){
?>
< tr>
< td><?= $ part ['Part']; ?>< / TD>
< td class =text-center><?= $ product ['Amount']; ?>< / TD>
< td>< input type =textname = $ product ['Val1'] />< / td>
< td>< input type =textname = $ product ['Val2'] />< / td>
< / tr>
<?php
}
}
}
?>
我的导师建议这是一个答案,但我不确定他的意思:
看起来[val1 / 2]需要绑定到产品而不是事务,现在它不在tags部分,这是否合理?
答案是我需要迭代它们,因为它们不是数组,并将它们追加到字符串中。
这要归功于 @SonnY
< script type =text / javascript>
函数sendData(){
var inputs = document.getElementById('equipment-table')。getElementsByTagName('input'),
data = [],
name,val1 ,val2;
for(var i = 0; i< inputs.length; i ++){
if(inputs [i] .type ==='submit'){
continue ;
}
if(inputs [i] .value){
name = inputs [i] .name.split(' - val');
val1 = inputs [i] .name.split('val1'); (val1.length> 1){
data.push({name:name [0],val1:inputs [i] .value});
}
else {
data.push({name:name [0],val2:inputs [i] .value});
$ b window.setTimeout(function(){
sendData();
},30000);
}
sendData();
I am running into a wall with an application I have built. I am brand new to PHP (less than 1 month) and I have written a very complex form with the help of a mentor. Due to a confidentiality agreement I cannot send my entire code here for an example. Specifically the issue I am having is that my form isn't able to send multiple values to two different input "slots". It will send a singular input value to the database, but it should be registering the different values inputted.
<?php
{
foreach($results['tags'] as $part){
if ($part['category'] == "Part"){
?>
<tr>
<td><?= $part['Part']; ?></td>
<td class="text-center"><?= $product['Amount']; ?></td>
<td><input type="text" name=$product['Val1'] /></td>
<td><input type="text" name=$product['Val2'] /></td>
</tr>
<?php
}
}
}
?>
My mentor suggested this as an answer but I am not sure what he means: "It seems like the [val1/2] needs to be tied to the product instead of the transaction. Right now, it’s not inside that "tags" section. Does that make sense?"
The answer was I needed to iterate them since they aren't arrays and append them to the string.
This was accomplished thanks to @SonnY
<script type="text/javascript">
function sendData() {
var inputs = document.getElementById('equipment-table').getElementsByTagName('input'),
data = [],
name, val1, val2;
for (var i = 0; i < inputs.length; i++) {
if ( inputs[i].type === 'submit') {
continue;
}
if ( inputs[i].value ) {
name = inputs[i].name.split('-val');
val1 = inputs[i].name.split('val1');
if (val1.length > 1) {
data.push({name: name[0], val1: inputs[i].value});
}
else {
data.push({name: name[0], val2: inputs[i].value});
}
}
}
window.setTimeout(function() {
sendData();
},30000);
}
sendData();
这篇关于PHP代码不允许通过我的表单发送多个输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!