0

这是html代码片段......

1)选中每个复选框后,值将发布到数据库。

2)但问题是当我检查 其他时,我需要获取文本框的值,它发布的是复选框的值而不是文本框的值

但我不知道我在哪里做错了......

<form action="purchase.php" name="form1" id="form1" method="POST">
    <ul class="n_ul"> <span>*</span>
What is your Primary goal?
        <br>
        <br>
        <li>
            <input name="goal" id="goal" value="Add a popular customer service to attract/retain more customers"
            type="checkbox">
        </li> <span>*</span>
Popular customer Services
        <br>
        <br>
        <li>
            <input name="goal" id="goal" value="Add a turnkey revenue sources for my location(s)"
            type="checkbox">
        </li> <span>*</span>
trunkey revenue source
        <br>
        <br>
        <li>
            <input name="goal" id="goal" type="checkbox" value="other">
        </li> <span>*</span>
Other (Please specify below)
        <br>
        <br>
        <input name="other" id="goal" type="text" class="new">
    </ul>
   <input type="submit" name=submit value="submit">
</form>

任何建议都可以接受......

4

3 回答 3

1

尝试类似的东西

$_POST['goal'] = ($_POST['goal']=='other') ? $_POST['other'] : $_POST['goal'];

仅当勾选“其他”单选时,才会用其他值覆盖目标值

html元素的id属性在页面上也应该是唯一的

编辑

你的问题有点含糊。似乎您可能希望在单击复选框按钮时提交表单。

  • 如果是这种情况,则不太可能填写其他字段,因为通常会在用户填充表单之前提交表单
  • 尝试添加按钮或输入以提交表单

像这样

<button type="submit">Submit</button>
于 2013-08-28T13:12:31.963 回答
0

你可以检查你的复选框的值,如果它等于其他,你可以从文本框中获取你的值。按照以下方式进行:

if (isset($_POST['goal']) && $_POST['goal'] == 'other')
{
    // do something with $_POST['other']
}
于 2013-08-28T13:03:55.097 回答
0

试试这个

<form action="" name="form1" id="form1" method="POST">
    <ul class="n_ul"> <span>*</span>
What is your Primary goal?
        <br>
        <br>
        <li>
            <input name="goal[]" id="goal" value="Add a popular customer service to attract/retain more customers"
            type="checkbox">
        </li> <span>*</span>
Popular customer Services
        <br>
        <br>
        <li>
            <input name="goal[]" id="goal" value="Add a turnkey revenue sources for my location(s)"
            type="checkbox">
        </li> <span>*</span>
trunkey revenue source
        <br>
        <br>
        <li>
            <input name="goal[]" id="goal" type="checkbox" value="other">
        </li> <span>*</span>
Other (Please specify below)
        <br>
        <br>
        <input name="other" id="goal" type="text" class="new">
    </ul>
   <input type="submit" name=submit value="submit">
</form>
<?php
$other="";
$goal=$_REQUEST['goal'];
if(in_array("other", $goal)){
$other=$_REQUEST['other'];
}
echo $other;
?>
于 2013-08-28T15:30:49.720 回答