Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以PHP格式发送数组值_Php_Html_Arrays_Forms - Fatal编程技术网

以PHP格式发送数组值

以PHP格式发送数组值,php,html,arrays,forms,Php,Html,Arrays,Forms,我有一个带有嵌入式PHP代码的HTML表单,它为数组中包含的每个值创建一个复选框。就这样, <?php $rows = array_map( 'str_getcsv', file( 'file.csv' ) ); $header = array_shift( $rows ); foreach ( $rows as $row ) { echo '<input type="checkbox" id="'.$row[0].'" name="'.$row[0].'"&g

我有一个带有嵌入式PHP代码的HTML表单,它为数组中包含的每个值创建一个复选框。就这样,

<?php 
  $rows = array_map( 'str_getcsv', file( 'file.csv' ) );
  $header = array_shift( $rows );
  foreach ( $rows as $row ) {
    echo '<input type="checkbox" id="'.$row[0].'" name="'.$row[0].'">
          <label for="'.$row[0].'">'.$row[0].'</label>
          <input type="number" name="'.$row[0].'" placeholder="Some text">';
  }
?>

现在,我想使用以下代码发送此表单,该代码插入到另一个PHP文件中:

<?php
  if( isset( $_POST ) == true && empty( $_POST ) == false ) {
    $account = $_POST['account'];
    $investment = $_POST['row[0]'];
    $password = $_POST['password'];
    $formcontent=" Account: $account \n $row[0]: $investment \n Password: $password";
    $recipient = "my@email.com";
    $subject = "My Form";
    $mailheader = "From: My Form <my@form.com>";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Some text";
  } 
?>

但它不起作用。单击“提交”按钮时,表单不会执行任何操作

我已经用纯HTML代码成功地检查了它,所以我想我在使用PHP时犯了一个错误

对于那些感兴趣的人,这里有一个到我的表格的链接:


编辑:正如@DavidJorHpan指出的那样,我已经删除了
preventDefault
,但我仍然被卡住了。我无法使我的form.php将
$row[0]
发送到我的电子邮件。

因为您使用了
preventDefault
,所以在您编写提交表单的代码之前,它不会提交表单

$("button").click(function(e) {
  e.preventDefault();
});
您可以删除该代码或添加类似的代码
$('form').submit()

正如David JorHpan在第二个答案中指出的,您必须从按钮单击事件中删除preventDefault()。这会阻止表单提交

对于每个复选框,都有相应的数字输入字段。虽然可能,但在“name”属性值中使用空格并不是一个好的做法。尝试用破折号或下划线替换这些空格。例如,您可以执行以下操作:

name="'.str_replace(' ','_',$row[0]).'"
id属性值也可以这样做

您的表单提交检查应该有效,但如果您按以下方式更改,则更有意义:

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
   // process here
}

完成这些更改后,请尝试加载页面并查看其运行情况

错误代码是什么?现在你再解释一下?你能告诉我们你得到的错误吗?@ÖzgürCanKaragöz我已经更新了我的问题。谢谢您的帮助。@JakeSylvestre请参阅评论#3。您使用的名称属性错误。像这样使用
name=“operative[]”
然后使用
value
属性来设置实际值也许我没有领会你的意思,但我没有使用
preventDefault
。你在
index.js中使用的
index.js
可以工作,但我仍然卡住了。请检查新的帖子编辑。谢谢。它能用,但我还是卡住了。请检查新的帖子编辑。谢谢。@engelnarciso请修复输入字段中的“名称”属性。您希望从这些复选框中获取多个值还是仅获取一个值?