避免php中的空行复选框

避免php中的空行复选框,php,html,Php,Html,我有html表单,其中有7个复选框。当所有的框都被选中时,它给出了良好的结果。尽管任何主体都会进行3或4次检查,但它会在结果之间显示空行。看起来很下流。任何机构都可以为此建议纠正代码 复选框的HTML代码: CONDITIONS: <br /> <input type="checkbox" name="c1" value="Invoice">Invoice <br /> <input type="checkbox" name="c2" value="LR

我有html表单,其中有7个复选框。当所有的框都被选中时,它给出了良好的结果。尽管任何主体都会进行3或4次检查,但它会在结果之间显示空行。看起来很下流。任何机构都可以为此建议纠正代码

复选框的HTML代码:

CONDITIONS: <br />
<input type="checkbox" name="c1" value="Invoice">Invoice <br />
<input type="checkbox" name="c2" value="LR copy">LR copy <br />
<input type="checkbox" name="c3" value="Test Reports">Test Reports<br />
<input type="checkbox" name="c4" value="Draft"> Draft<br />
<input type="checkbox" name="c5" value="Check-list">Check-List <br />
<input type="text" name="c6" placeholder=" Add any" maxlength="25" size="40"><br />
<input type="text" name="c7"  placeholder=" Add any clause"  maxlength="25" size="40">
条件:
发票
LR副本
测试报告
草稿
检查表

上述复选框的php代码:

    <html>
<head>
<style type="text/css">

table { margin: 1em 0 0 0; border-collapse: collapse; }
td {margin: 5px 0 0 0;padding: .4em ;  border: 0px solid; height: 12px; }
tr td:first-child {font-weight: bold; width: 250px; color: black; height: 10px; font-size: 18px;}
tr td:last-child {width: 450px; color: blue;height: 10px; font-size: 18px; }

p {margin: 5px 0 0 20px; width: 700px; line height: 20px; text-align: justify; font-size:105%;
font-family: Arial, "Lucida Sans Unicode", Verdana, sans-serif;}

#trim {margin: 5px 0 0 20px; width: 700px; line height: 20px; text-align: center; font-size:150%;
font-family: Arial, "Lucida Sans Unicode", Verdana, sans-serif;}

.z{ margin: 5px 0 0 20px; width: 700px;}
.z1{ margin: 5px 0 0 20px; width: 700px;}

</style>

</head>
<body>

<div id="trim">
<b> FORMAT  </b>    
<hr size="2" noshade>                      
</div>


<?

$k1 = strtoupper($_REQUEST['k1']);
$k2 = strtoupper($_REQUEST['k2']);
$k3 = strtoupper($_REQUEST['k3']);
$k4 = strtoupper($_REQUEST['k4']);
$k5 = strtoupper($_REQUEST['k5']);
$k6 = strtoupper($_REQUEST['k6']);
$k7 = strtoupper($_REQUEST['k7']);
$k22 = strtoupper($_REQUEST['k22']);
$k23 = strtoupper($_REQUEST['k23']);
$k8 = strtoupper($_REQUEST['k8']);
$k9 = strtoupper($_REQUEST['k9']);
$k10 = strtoupper($_REQUEST['k10']);
$k11 = strtoupper($_REQUEST['k11']);
$k12 = strtoupper($_REQUEST['k12']);
$k13 = strtoupper($_REQUEST['k13']);
$k14 = strtoupper($_REQUEST['k14']);
$k15 = strtoupper($_REQUEST['k15']);
$k16 = strtoupper($_REQUEST['k16']);
$c6 = strtoupper($_REQUEST['c6']);
$c7 = strtoupper($_REQUEST['c7']);
$k19 = strtoupper($_REQUEST['k19']);
$k20 = strtoupper($_REQUEST['k20']);
$k21 = strtoupper($_REQUEST['k21']);
$r1 = strtoupper($_REQUEST['r1']);
$r2 = strtoupper($_REQUEST['r2']);
$r3 = strtoupper($_REQUEST['r3']);
$r4 = strtoupper($_REQUEST['r4']);
$r5 = strtoupper($_REQUEST['r5']);
$r6 = strtoupper($_REQUEST['r6']);
$r7 = strtoupper($_REQUEST['r7']);
$r8 = strtoupper($_REQUEST['r8']);
$r9 = strtoupper($_REQUEST['r9']);
$r10 = strtoupper($_REQUEST['r10']);
$c1 = strtoupper($_REQUEST['c1']);
$c2 = strtoupper($_REQUEST['c2']);
$c3 = strtoupper($_REQUEST['c3']);
$c4 = strtoupper($_REQUEST['c4']);
$c5 = strtoupper($_REQUEST['c5']);

$c8 = strtoupper($_REQUEST['c8']);
$c9 = strtoupper($_REQUEST['c9']);
$c10 = strtoupper($_REQUEST['c10']);
$c11 = strtoupper($_REQUEST['c11']);
$c12 = strtoupper($_REQUEST['c12']);
$c13 = strtoupper($_REQUEST['c13']);
$c14 = strtoupper($_REQUEST['c14']);
$c15 = strtoupper($_REQUEST['c15']);
$c16 = strtoupper($_REQUEST['c16']);
$c17 = strtoupper($_REQUEST['c17']);
$c18 = strtoupper($_REQUEST['c18']);
$c19 = strtoupper($_REQUEST['c19']);
$c20 = strtoupper($_REQUEST['c20']);
$c21 = strtoupper($_REQUEST['c21']);
$c22 = strtoupper($_REQUEST['c22']);
$c23 = strtoupper($_REQUEST['c23']);
$c24 = strtoupper($_REQUEST['c24']);
$c25 = strtoupper($_REQUEST['c25']);
$p1= strtoupper($_REQUEST['p1']);
$p2 = strtoupper($_REQUEST['p2']);

if(empty($k2)){$kk="  "; }else{$kk="(Code: $k2)";}


$html = "<p> <div class='z1'>
<b><u> PROJECT DETAILS </u></b>
<table>
<tr><td> Project Name: </td>  <td > $k1 &nbsp; &nbsp; $kk</td></tr>
<tr><td> Purchase Order no:</td> <td > $k3 &nbsp; &nbsp;Dtd: $k4</td></tr>
<tr><td>Total Order Value:</td>  <td >$k6 </td></tr>
<tr><td> Materials Ordered </td> <td >$k5 </td></tr>
<tr><td> Supplier Details: </td> <td >$k22  <br /> $k23</td></tr>
</table>
<br /><b><u> DISPATCH CONDITIONS </u></b>
<table>
<tr><td> Shipment from: </td> <td > $k11</td></tr>
<tr><td> Shipment to: </td> <td >$k12 </td></tr>
<tr><td> Dispatch starting date: </td> <td >$k9 </td></tr>
<tr><td> Last date of dispatch: </td> <td >$k10 </td></tr>
<tr><td> Part-Shipment: </td> <td >$r1 </td></tr>
<tr><td> Part-Transshipment: </td> <td > $r2</td></tr>
<tr><td> Transport Charges: </td> <td > $r4</td></tr>
<tr><td> Insurance Charges: </td> <td > $r3</td></tr>
<tr><td> Basis of price: </td> <td > $r5</td></tr>
</table>

<br /><b><u> BANK DETAILS </u></b>
<table>
<tr><td> L/C amount: </td> <td > $k8 <br /> Rs. $k30 </td></tr>
<tr><td> Usance period: </td> <td > $r9  Days from the date of dispatch.</td></tr>
<tr><td> Usance interest: </td> <td>$k15 Days to Supplier A/c. and  $k16 Days to Buyer A/c.</td></tr>
<tr><td> Usance interest charges:  </td> <td >Not more than $k14 % p.a </td></tr>
<tr><td> L/C Charges: </td> <td > Opening charges to $r7 and discount charges to $r8</td></tr>
<tr><td> Negotiation to be done: </td> <td > within $r10  Days from the date of dispatch.</td></tr>
<tr><td> Place of Expiry: </td> <td >  $k21</td></tr>
</table>

<br /><b><u> DOCUMENTS REQUIRED:</u></b>
<ul><li>$c1 
</li><li>$c2 
</li><li>$c3
</li><li>$c4 
</li><li>$c5 
</li><li>$c6
</li><li>$c7 
</li></ul>
<br /><b><u> L/C CONDITIONS </u></b>
<ul><li>
$c8 </li><li>
$c9 </li><li>
$c10</li><li>
$c11 </li><li>
$c12</li><li>
$c13 </li><li>
$c22 </li><li>
$c23 </li></ul>

<br /><b><u> ADDITIONAL CONDITIONS </u></b>
<ul><li>
$c14 </li><li>
$c15 </li><li>
$c16 </li><li>
$c17 </li><li>
$c18 </li><li>
$c19 </li><li>
$c20 </li><li>
$c21 </li><li>
$c24 </li><li>
$c25 </li><li>
$k19 </li><li>
$k20 </li></ul>

</div></p>";

$html .= "<div class='z'> <hr /> Place: <b>".$p1."</b></div>";
$html .= "<div class='z'> Date:  $p2 <div style='float:right;font-size: 12pt'><i> (Authorized Signature ) </i></div></div>";


print($html);

?>

</body>
</html>

表{边距:1em 0;边框折叠:折叠;}
td{边距:5px 0;填充:.4em;边框:0px实心;高度:12px;}
tr td:first child{字体大小:粗体;宽度:250px;颜色:黑色;高度:10px;字体大小:18px;}
tr td:last child{宽度:450px;颜色:蓝色;高度:10px;字体大小:18px;}
页边距:5px020px;宽度:700px;行高:20px;文本对齐:对齐;字体大小:105%;
字体系列:Arial,“Lucida Sans Unicode”,Verdana,Sans serif;}
#修剪{边距:5px020px;宽度:700px;行高:20px;文本对齐:居中;字体大小:150%;
字体系列:Arial,“Lucida Sans Unicode”,Verdana,Sans serif;}
.z{边距:5px020px;宽度:700px;}
.z1{边距:5px020px;宽度:700px;}
格式


你总是重复所有的台词。当某些值为空时,将只有空行(列表项)。因此,您必须检查这些值是否存在。小例子:

    <?

    $html = '<p>CONDITIONS:</p><ul>';

    function echoRow(&$html, $val) {

      if (isset($val) && !empty($val))
        $html .= '<li>' . $val . '</li>';  
    }


    echoRow($c1);
    echoRow($c2);
    echoRow($c3);
    echoRow($c4);
    echoRow($c5);
    echoRow($c6);
    echoRow($c7);

    $html .= '</ul>';

    print($html);

?>

这是因为当复选框未选中时,其值不会发送到服务器。例如,如果未选中C1,则不会将其发送到$\u POST值中。您可以做的是检查是否设置了每个复选框,并仅显示其值存在的复选框。如果需要,可以为未设置的复选框显示备选消息。你可以这样做

    $html="<ul>";

    if(isset($c1))
          $html.="<li>$c1</li>"
    else 
    {
     //do nothing or show alternative message 
     $html.="<li>Invoice not selected</li>"
    }

// do same for $c2....$c7
$html.="</ul>";
print($html);
$html=“
    ”; 若有(isset($c1)) $html.=“
  • $c1
  • ” 其他的 { //不执行任何操作或显示其他消息 $html.=“
  • 未选择发票
  • ” } //对$c2….$c7执行同样的操作 $html.=“
”; 打印(html);
我在PHP代码中有很多HTML数据。如果你不能理解你的意思,请不要用echoRow,请建议打印($html)。。??
echoRow
是用于检查值并将其添加到
$html
变量的唯一帮助函数。然后你只需要把它打印出来作为浏览器..得到代码了,但我还是有疑问。另一个复选框有12个值。如果我在$html中使用
    ,它将不会给出正确的结果,而是有任何下面给出了整个php代码。你能纠正一下吗?