0

私はjqueryモバイルアプリに取り組んでいます。今、私はユーザーがチェックリストを送信できるようにしたいと考えています。だから私はチェックリストを作りました、そして今私はそれを電子メールアドレスに送らなければなりません. 誰かがこれを行う方法を教えてもらえますか? PHP を使用する必要があることはわかっていますが、PHP のスキルはそれほど高くありません。お問い合わせフォームを作成して送信する方法は知っていますが、お問い合わせフォームには、入力して送信する必要があるチェックボックスがありません。

これは私の HTML ページのコードです:

<form id="form1" method="post" action="checklist.php">
<fieldset class="ui-corner-all" >

<div class="ui-checkbox">
<input id="checkbox-t0" class="custom" type="checkbox" name="checkbox-t0">

<label for="checkbox-t0">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">Vehicle checked for damage</span>
</span>
</label>
</div>

<div class="ui-checkbox">
<input id="checkbox-t1b" class="custom" type="checkbox" name="checkbox-t1b">
<label for="checkbox-t1b">
<span class="ui-btn-inner">
<span class="ui-btn-text">Oil checked</span>
</span>
</label>
</div>

<div class="ui-input-text">
<label for="achternaam" data-theme="a">
<span class="ui-btn-inner">
<span class="textbox"> Last name: </span></span>
</label>
<input type="text" name="achternaam">
</div>
</fieldset>

<fieldset>
<div class="ui-block-a"><button type="submit" name="submit"  data-theme="a" >Send</button></div>
</fieldset></form>

他にもチェックボックスがありますが、ここで 100 個のチェックボックスを表示する必要はありません。

では、フォームを特定の電子メール アドレスに送信するにはどうすればよいでしょうか。どんな助けでも素晴らしいでしょう、ありがとう!

私はオランダ人なので、いくつかの単語はオランダ語で書かれています。

4

1 に答える 1

0

Do as you would normally do with your contact forms, a check box is just another type of input, the only difference is that if its not checked then no value will be sent in the POST and if no value attribute is set for the checkbox then it will default to on.

The simplest way to check if the value is not present in the POST (e.g not checked) is to build an array of all your inputs, and then loop through that, checking that each one is present within the POST array, if not handle accordingly, this will also eliminate unwanted POST values that don't want to handle.

<?php 
//Check for POST
if($_SERVER['REQUEST_METHOD']=='POST'){
    //All your inputs
    $expecting = array('achternaam','checkbox-t0','checkbox-t1b');
    //Start building your email
    $email_content = '';
    foreach($expecting as $input){
        //Is checkbox?
        if(substr($input,0,8)=='checkbox'){
            $email_content .= ucfirst($input).':'.(isset($_POST[$input]) && $_POST[$input] == 'on' ? 'True' : 'False'.'<br />');

        //achternaam and other non  checkbox-* keys
        }else{
            $email_content .= ucfirst($input).':'.(!empty($_POST[$input]) ? $_POST[$input] : 'Unknown').'<br />';
        }
    }

    /* Achternaam:Lawrence<br />Checkbox-t0:False<br />Checkbox-t1b:False<br /> */
    print_r($email_content);

    /* Mail it
    if(mail('the_email_to_send_too@example.com', 'My Subject', wordwrap($email_content))){
       //mail sent
    }else{
       //mail failed 2 send
    }
    */
}
?>
于 2012-11-01T13:50:09.127 に答える