dongqin1861 2013-11-13 12:09
浏览 65
已采纳

在PHP表单处理中苦苦挣扎

Can anyone help with a form problem that I just can't fathom? I have a group of checkboxes whose values I can't get to show up in the resulting mail.

This is the method I'm using to set the variables:

    $benefit01  = ($_POST['benefit_01']);
$benefit02  = ($_POST['benefit_02']);
$benefit03  = ($_POST['benefit_03']);
$benefit04  = ($_POST['benefit_04']);
$benefit05  = ($_POST['benefit_05']);
$benefit06  = ($_POST['benefit_06']);

$property   = addslashes($_POST['property']);
$owner      = addslashes($_POST['owner']);
$mainHeating    = addslashes($_POST['Heating_mainHeating_answer']);
$boiler_working = addslashes($_POST['boiler_working']);
$boiler_age = addslashes($_POST['boiler_age']);

$postcode   = addslashes($_POST['postcode']);
$address1   = addslashes($_POST['address1']);
$address2   = addslashes($_POST['address2']);
$address3   = addslashes($_POST['address3']);
$city       = addslashes($_POST['town']);
$county     = addslashes($_POST['county']);

$name       = addslashes($_POST['firstName']);
$surname    = addslashes($_POST['surname']);
$email      = addslashes($_POST['email']);
$phone      = addslashes($_POST['phonenum']);


$type   = addslashes($_POST['type']);
$time   =   $_POST['time'];
$src = $_POST['urlsrc'] ;

$benefits   = $benefit01." ".$benefit02." ".$benefit03." ".$benefit04." ".$benefit05." ".$benefit06;
$address = $address1." ".$address2;
$note = "Benefits: ".$benefits.". Property Type: ".$property.". Home Owner: ".$owner.". Type of Heating: ".$mainHeating.". Boiler Working: ".$boiler_working.". Boiler Age: ".$boiler_age.". Timescales: ".$time.". Address Line 3: ".$address3;

So the "benefits" are checkboxes. I had tried naming them all the same to create an array then imploding the values but that didn't work either. Ultimately this data is sent to a dbase which is why most of the info is dumped into a $note variable.

I don't know much about this and have taken this example from a working (albeit simplified) form. Any assistance appreciated.

** Small sample of the form added below:

    <input name="ctl00_chkBenefit" type="checkbox" id="benefit_01" class="checkbox-benefit" value="Child Tax Credit" />

Child Tax Credit (where the relevant income is £15,860 or less)

     <input name="ctl01_chkBenefit" type="checkbox" id="benefit_02" class="checkbox-benefit" value="State Pension Credit" />

State Pension Credit

  • 写回答

4条回答 默认 最新

  • dounan4479 2013-11-13 12:12
    关注

    Is your checkbox's HTML like this?

    <input type="checkbox" name="benefit_01" value="Benefit 01" /> Benefit 01
    

    Then if that checkbox will be checked by user, $_POST['benefit_01'] will be the value of that checkbox - Benefit 01.

    If it will be not checked, $_POST['benefit_01'] will be not set.

    EDITED 1:

    And that all you should have in <form>, with setted method and action:

    <form action="index.php" method="post">
         <input name="ctl00_chkBenefit" type="checkbox" id="benefit_01" class="checkbox-benefit" value="Child Tax Credit" />
    </form>
    

    EDITED 2:

    You have different name for that checkboxes. You used in your $_POST theirs id, not name.

    Change your code to this:

    $benefit01  = ($_POST['ctl00_chkBenefit']);
    $benefit02  = ($_POST['ctl01_chkBenefit']);
    $benefit03  = ($_POST['ctl02_chkBenefit']);
    $benefit04  = ($_POST['ctl03_chkBenefit']);
    $benefit05  = ($_POST['ctl04_chkBenefit']);
    $benefit06  = ($_POST['ctl05_chkBenefit']);
    

    Now it will work for 100% :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上