Php 如何在不点击按钮的情况下发布$\u帖子?
以前,我有一个表单,它有一个单选按钮,当然,当按下submit时,它会提交单选按钮中的值 但是如果我不再需要单选按钮,我该怎么做呢?按下表格单元格或行时,是否会在不使用提交按钮的情况下自动将值提交到下一页Php 如何在不点击按钮的情况下发布$\u帖子?,php,jquery,html,forms,Php,Jquery,Html,Forms,以前,我有一个表单,它有一个单选按钮,当然,当按下submit时,它会提交单选按钮中的值 但是如果我不再需要单选按钮,我该怎么做呢?按下表格单元格或行时,是否会在不使用提交按钮的情况下自动将值提交到下一页 <form method="post" action="billing.php"> <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
<form method="post" action="billing.php">
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td>
<td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p>
<div id='price'> Additional ₱250 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
<td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p>
<div id='price'> Free!! </div></td>
</tr>
</table>
</form>
value=“拾取”>
亲自到我们办公室取货。免费的。办公时间:上午10:00至下午5:00
自由的
如何在不使用submit按钮或单选按钮的情况下使其提交,因为当我按下该行时,它会将值提交到下一页,而我会转到下一页
多谢各位
编辑
value=“拾取”>
接电话。您有5天的预订期。您在提货时付款
只需使用行提交即可。考虑这个标记:
<form method="post" action="billing.php">
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
<tr class="row_submit">
<!-- ^^ simple class assignment -->
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td>
<td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p>
<div id='price'> Additional ₱250 </div></td>
</tr>
<tr class="row_submit">
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
<td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p>
<div id='price'> Free!! </div></td>
</tr>
</table>
</form>
value=“拾取”>
亲自到我们办公室取货。免费的。办公时间:上午10:00至下午5:00
自由的
然后在你的JS上:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('tr.row_submit').on('click', function(e){
$('form').submit();
});
});
</script>
$(文档).ready(函数(){
$('tr.row_submit')。在('click',函数(e)上{
$('form').submit();
});
});
然后在PHP上:
$info_table = array(
'LBC' => array(
'price' => 250,
'payment' => 'BPI',
),
'PickUp' => array(
'price' => 0,
'payment' => '',
),
);
if(isset($_POST['carrier'])){
echo $_POST['carrier'];
$price = $info_table[$_POST['carrier']]['price'];
$payment = $info_table[$_POST['carrier']]['payment'];
echo '<br/>' . $price . '<br/>';
echo $payment;
}
$info\u table=数组(
“LBC”=>数组(
“价格”=>250,
“付款”=>“BPI”,
),
“拾取”=>阵列(
“价格”=>0,
'付款'=>'',
),
);
如果(isset($_POST['carrier'])){
echo$_POST['carrier'];
$price=$info_table[$_POST['carrier']['price'];
$payment=$info_表[$_POST['carrier']]['payment'];
回显“
”。$price.“
”;
回音$付款;
}
试试这个:
<script type="text/javascript">
function submit(){
var data = $("form[action=billing.php]").serialize();
$.ajax({
url: "billing.php",
type: "POST",
data: data,
success: function(out){
$(body).html(out);
}
});
}
$(document).ready(function(){
$('tr.row_submit').click(function(){submit();});
}
</script>
函数提交(){
var data=$(“form[action=billing.php]”)。serialize();
$.ajax({
url:“billing.php”,
类型:“POST”,
数据:数据,
成功:功能(输出){
$(body).html(out);
}
});
}
$(文档).ready(函数(){
$('tr.row_submit')。单击(函数(){submit();});
}
我希望它能工作!然后使用javascript(jquery标记)要触发按行提交,ClickDos有帮助吗?只是澄清一下,因为OP对PHP/Web来说似乎是新的。您应该仔细阅读有关清理输入的内容,不要直接使用$u POST变量,否则这是正确的方法it@DaOgre如果你想准备陈述的话,我们会告诉你,当然,无论如何,这是一个完全不同的话题,它会太长了,但我当然理解你的想法。呵呵。谢谢。嗯。使用这个值时,我如何放置两个值?因为我还需要提交$payment和$CARRER,所以代码中不包括它。这就是为什么我不喜欢使用单选按钮,因为只能提交1个,或者我错了吗?谢谢。@VinceAgno你真的不喜欢吗不需要在表单中使用另一个输入元素,只需使用与收音机对应的预定义数组即可button@VinceAgnoeto bro检查我对PHP部分的修订请扩展您的答案,解释您的代码的作用。将OP教给fish:)@dimo414它选择billing form元素并以carrier=value的方式序列化其输入,然后在使用类“row_submit”单击tr后通过xhr提交此表单,最后将使用表单响应刷新文档正文
<script type="text/javascript">
function submit(){
var data = $("form[action=billing.php]").serialize();
$.ajax({
url: "billing.php",
type: "POST",
data: data,
success: function(out){
$(body).html(out);
}
});
}
$(document).ready(function(){
$('tr.row_submit').click(function(){submit();});
}
</script>