PHP代码不允许通过我的表单发送多个输入值 [英] PHP code isn't allowing multiple input values to send through my form

查看:62
本文介绍了PHP代码不允许通过我的表单发送多个输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用我已经建立的应用程序进入墙壁。我是PHP新手(不到1个月),我在导师的帮助下撰写了一份非常复杂的表格。由于保密协议的原因,我无法在此处举例说明我的整个代码。具体而言,我遇到的问题是我的表单无法将多个值发送到两个不同的输入插槽。它会向数据库发送一个单一的输入值,但它应该注册不同的输入值。

 <?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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆