1

どのラジオボックスがチェックされているかをphpフォームに表示したいと思います。言い換えれば、誰かが私のウェブサイトから電子メールで私に連絡したとき、彼らがチェックしたラジオボックスを表示したいと思います。私はすべてを試しましたが、動作させることができません!

これまでの HTML コード -

<table width="308" border="0">
      <label>
        <input type="radio" name="servicetype[]" value="checkbox" id="Technical Support" />
        Technical Support</label>

      <label>
        <input type="radio" name="servicetype[]" value="checkbox" id="Information Services" />
        Information Services</label>
  <tr>
    <td align="left">
   <input name="Submit" type="submit" id="Submit" class="contact-class2" value="Send"/>
    </td>
  </tr>
</table>
    </form>

これまでのPHP

<?php
 $field_name = $_POST['cf_name'];
 $field_email = $_POST['cf_email'];
 $field_message = $_POST['cf_message'];

 $mail_to = 'www.example.com';
 $subject = 'hello';

 $servicetype = join(", ", $_REQUEST["servicetype"]);
 if (isset($_POST['servicetype'])) {
    foreach ($_POST['servicetype'] as $key => $val) {
        // do what you need
    }
 }


 $body_message = ''.$field_message."\n"."\n";
 $body_message .= 'From: '.$field_name;

 $headers = 'From: '.$field_email."\r\n";
 $headers .= 'Reply-To: '.$field_email."\r\n";

 $mail_status = mail($mail_to, $subject, $body_message, $headers  );



 if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        window.location = 'Contact form.html';
    </script>
 <?php
 }
 else { ?>
    <script language="javascript" type="text/javascript">
        window.location = 'Contact form.html';
    </script>
 <?php
 }
 ?>
4

1 に答える 1

2

チェックボックスの入力を正しく作成していません。value属性は、チェックボックスの表示された「名前」である必要があります。

    <input type="checkbox" name="servicetype[]" value="Technical Support" id="Technical Support" />
                 ^^^^^^^^                              ^^^^^^^^^^^^^^^^^

valueフォームと一緒に送信されるのはそれです。現状では、「チェックボックス」という単語を送信するだけで、どのチェックボックスが選択されているかを知る方法はありません。

メールアドレスは次のとおりです。

$body_message = "blah blah blah. Requested services: " . implode(',' $_POST['servicetype']);
于 2013-05-14T17:27:42.137 に答える