【发布时间】:2018-05-27 23:31:09
【问题描述】:
我有一个带有嵌入式 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 时犯了一个错误。
对于那些感兴趣的人,这里是我的表单的链接: Example
编辑:正如@DavidJorHpan 所指出的,我已经删除了preventDefault,但我仍然卡住了。我无法让我的 form.php 将 $row[0] 发送到我的电子邮件。
【问题讨论】:
-
错误代码是什么?现在你再解释一下?
-
你能告诉我们你得到的错误吗?
-
@ÖzgürCanKaragöz 我已经更新了我的问题。感谢您的帮助。
-
@JakeSylvestre 请参阅评论 #3。
-
您使用的名称属性错误。像这样使用
name="operative[]"然后使用value属性设置实际值