如何使用php获取所选文本框值
我有一个属性列表,我得到了符合我的选择标准的用户列表 我需要向所选用户发送邮件 我选中所有选项来检查每个用户 我有文本框,每个用户都可以更改租金值 我选择了某个用户,然后单击“发送我需要发送文本框中有值的邮件” 我想在表单提交代码中获取所选文本框值 在上图中,每个属性都有一个复选框,checkbob用于选中所有属性。我有一个价格文本框 当我通过选择一些属性单击“发送”时,我想发送一封邮件,告知已发布的租金值 下面是示例代码如何使用php获取所选文本框值,php,jquery,forms,post,checkbox,Php,Jquery,Forms,Post,Checkbox,我有一个属性列表,我得到了符合我的选择标准的用户列表 我需要向所选用户发送邮件 我选中所有选项来检查每个用户 我有文本框,每个用户都可以更改租金值 我选择了某个用户,然后单击“发送我需要发送文本框中有值的邮件” 我想在表单提交代码中获取所选文本框值 在上图中,每个属性都有一个复选框,checkbob用于选中所有属性。我有一个价格文本框 当我通过选择一些属性单击“发送”时,我想发送一封邮件,告知已发布的租金值 下面是示例代码 while($tenant = mysqli_fetch_arr
while($tenant = mysqli_fetch_array($result))
{
echo '
<tr>
<td>
<a href="property.php?id='.$pro['id'].'"><img src="'.(($pro['image_1']) ? $pro['image_1'] : 'images/placeholder.png').'" alt="" width="100"></a>
</td>
<td><a href="#">'.$name['name'].$tenant['tenant_id'].' </a><br> '.$pro['name'].'</td>
<td><b>'.$tenant['lease_exp'].'</b><br><i>'.$pro['ready'].'</i></td>
<td>'.$pro['type'].'</td>
<td><div class="price"><strong>$</strong><span>'.$tenant['rent_from'].'-'.$tenant['rent_to'].'</span></div><br><br><input type="text" name="new_rent'.$i.'" value='.$pro['rent'].' class="form-control" style="width:30%;" ></td>
<td>
<input type="checkbox" name="rent[]" id="rent'.$i.'" value="'.$tenant['tenant_id'].'"> Send
</td>
</tr>
';
}
<script>
$(document).ready(function() {
$('#all').change(function(){
var ckb_status = $("#all").prop('checked');
$('input[type="checkbox"]').prop("checked", ckb_status );
});
});
</script>
if(isset($_POST['submit'])) {
if(!empty($_POST['rent'])) {
print_r($_POST);
foreach($_POST['rent'] as $check) {
$tenant_profile = "SELECT * FROM tenant where id=".$check;
$prof = mysqli_query($link, $tenant_profile);
$profile = mysqli_fetch_array($prof);
//echo $tenant_profile;
//echo "</br>";
//echo $pro['name'];
echo $_POST['new_rent'];echo "</br>";
$to = $profile['email'];
$subject = 'Price Change Alert';
$header = "From: ".ADMIN_EMAIL."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
$message = '' ;
$message .= "<div><p>Dear User there is a price drop for the property
<a href='".$_SERVER['SERVER_NAME']."/property.php?id=".$pro['id']."'>".$pro['name']."</a></p>
<p>Owner offering you ".$_POST['new_rent'].". </p>
<p>please contact the owner for the complete details. </p>
<p>Owner email id:#</div>";
$mail1 = mail($to, $subject, $message, $header);
if($mail1) { echo 'mail sent successfully'; }
}// foreach
} //empty checkbox check
else { echo "Plase Check Any Result"; }
}//submit
$POST['new_rent']找不到任何内容,因为文本框名为new_rent$i
更好的方法是对复选框和文本框使用数组名称,并对两者使用相同的$i作为数组索引
$i = 0;
while($tenant = mysqli_fetch_array($result))
{
echo '
<tr>
<td>
<a href="property.php?id='.$pro['id'].'"><img src="'.(($pro['image_1']) ? $pro['image_1'] : 'images/placeholder.png').'" alt="" width="100"></a>
</td>
<td><a href="#">'.$name['name'].$tenant['tenant_id'].' </a><br> '.$pro['name'].'</td>
<td><b>'.$tenant['lease_exp'].'</b><br><i>'.$pro['ready'].'</i></td>
<td>'.$pro['type'].'</td>
<td><div class="price"><strong>$</strong><span>'.$tenant['rent_from'].'-'.$tenant['rent_to'].'</span></div><br><br><input type="text" name="new_rent['.$i.']" value='.$pro['rent'].' class="form-control" style="width:30%;" ></td>
<td>
<input type="checkbox" name="rent['.$i.']" id="rent'.$i.'" value="'.$tenant['tenant_id'].'"> Send
</td>
</tr>
';
$i++;
}
然后,您可以在数组中循环并获得相应的输入
foreach ($_POST['rent'] as $i => $check) {
$new_rent = $_POST['new_rent'][$i];
$tenant_profile = "SELECT * FROM tenant where id=".$check;
$prof = mysqli_query($link, $tenant_profile);
$profile = mysqli_fetch_array($prof);
//echo $tenant_profile;
//echo "</br>";
//echo $pro['name'];
echo $_POST['new_rent'];echo "</br>";
$to = $profile['email'];
$subject = 'Price Change Alert';
$header = "From: ".ADMIN_EMAIL."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
$message = '' ;
$message .= "<div><p>Dear User there is a price drop for the property
<a href='".$_SERVER['SERVER_NAME']."/property.php?id=".$pro['id']."'>".$pro['name']."</a></p>
<p>Owner offering you ".$new_rent.". </p>
<p>please contact the owner for the complete details. </p>
<p>Owner email id:#</div>";
$mail1 = mail($to, $subject, $message, $header);
if($mail1) { echo 'mail sent successfully'; }
}// foreach
问题是什么?你说的文本框在哪里?他用文本框代替了复选框@AedixRhinedale@AedixRhinedale复选框用于选择物业,每个物业都有一个文本框用于添加租金。我希望租金值以submitWhere的形式存在。在创建表行的while循环中,您在何处增加$I?为什么他需要获得复选框的计数?foreach会自动执行此操作。谢谢您的代码。但它不起作用。我得到的是单个值或第一个选定值,而文本框值未提交到循环。我犯了一个错误。我把$I放在字符串中,但没有注意到它是用单引号括起来的,所以变量没有展开。我将其更改为使用串联。
foreach ($_POST['rent'] as $i => $check) {
$new_rent = $_POST['new_rent'][$i];
$tenant_profile = "SELECT * FROM tenant where id=".$check;
$prof = mysqli_query($link, $tenant_profile);
$profile = mysqli_fetch_array($prof);
//echo $tenant_profile;
//echo "</br>";
//echo $pro['name'];
echo $_POST['new_rent'];echo "</br>";
$to = $profile['email'];
$subject = 'Price Change Alert';
$header = "From: ".ADMIN_EMAIL."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
$message = '' ;
$message .= "<div><p>Dear User there is a price drop for the property
<a href='".$_SERVER['SERVER_NAME']."/property.php?id=".$pro['id']."'>".$pro['name']."</a></p>
<p>Owner offering you ".$new_rent.". </p>
<p>please contact the owner for the complete details. </p>
<p>Owner email id:#</div>";
$mail1 = mail($to, $subject, $message, $header);
if($mail1) { echo 'mail sent successfully'; }
}// foreach