PHP单选按钮内部回声

时间:2013-03-31 23:13:58

标签: php button radio

    echo    "<form class='custom'>";
foreach ($prices->item as $item){
      $ongkir = $item->value;
      $transfer = $total_jne * 1000;
      $transfer_rp = $transfer + $ongkir;
      $jne = $item->service;
      $checked = ($jne == $_POST['ongkir'])? ' checked="checked"' : '';
      echo  "<tr><td><label for='$item'>
      <input class='custom' name='ongkir' $checked type='radio' id='ongkir'> $jne</label></td>";
      echo  "<td>Rp. $ongkir</td>";
      echo  "<td>Rp. $transfer_rp</td></tr>";}
      echo  "</table><hr></form>" ;
    }

大家好,如何使用按钮将带有值='$ transfer_rp'的“已检查”发布到另一个php文件? :(

1 个答案:

答案 0 :(得分:1)

收音机输入将显示为“true”或“false”,而不是其name属性的值,请尝试

$checked = ($jne == 'ongkir' && isset($_POST['ongkir']) && $_POST['ongkir'] == "true" )? ' checked="checked"' : '';

或者因为这是丑陋的

$checked = '';
if( $jne == 'ongkir' && isset($_POST['ongkir']) && $_POST['ongkir'] == "true" ){
    $checked = 'checked="checked"';
}