1

お問い合わせフォームを作成しようとしていますが、input type=text の検証を行う必要がありますが、いくつかの間違いがあるようで、見つけることができません。手伝って頂けますか?コードは次のとおりです。

    <td>
Name*:<input type="text" name="name" id='name2' class="name1" />
</td>
<td>
Email*:<input type='text' name="email" class="email1" id='email2'/>
</td>
</tr>
<tr>
<td colspan="2" rowspan="2">
Message*: <br />

<textarea name='msg' style="float:right;" class="msg1" id='msg2'>
</textarea>
</td>

そしてここ:

<?PHP
$nml = strlen($_POST['name']);
$eml = strlen($_POST['email']);
$msgl = strlen($_POST['msg']);

if(isset($_GET['sent'])) {
    if($nml<1) { 
    if($eml<1) {
    if($msgl<1) {   
        exit("<script>document.getElementById('name2').style.borderColor='red'; document.getElementById('email2').style.borderColor='red'; document.getElementById('msg2').style.borderColor='red';</script><center><font color='red'>Name*, Email* and Message* fields are required</font></center>");
    }
    exit("<script>document.getElementById('name2').style.borderColor='red'; document.getElementById('email2').style.borderColor='red';</script><center><font color='red'>Name* and Email* fields are required</font></center>");
    }
    exit("<script>document.getElementById('name2').style.borderColor='red'; <center><font color='red'>Name* field is required</font></center>");
    }
    if($eml<1) {
        if($msgl<1) {
            if($nml<1) {
        exit("<script>document.getElementById('email2').style.borderColor='red'; document.getElementById('name2').style.borderColor='red'; document.getElementById('msg2').style.borderColor='red';</script><center><font color='red'>Email*, Name * and Message* fields are required</font></center>");
            }
            exit("<script>document.getElementById('email2').style.borderColor='red'; document.getElementById('msg2').style.borderColor='red';</script><center><font color='red'>Email* and Message* fields are required</font></center>");
    }
        exit("<script>document.getElementById('email2').style.borderColor='red';</script><center><font color='red'>Email* field is required</font></center>");
    }
    if($msgl<1) {
        if($nml<1) {
            if($eml<1) {
                exit("<script>document.getElementById('msg2').style.borderColor='red'; document.getElementById('name2').style.borderColor='red'; document.getElementById('email2').style.borderColor='red';</script><center><font color='FF0000'>Message*, Name* and Email* Fields are required</font></center>");
            }
            exit("<script>document.getElementById('msg2').style.borderColor='red'; document.getElementById('name2').style.borderColor='red';</script><center><font color='FF0000'>Message* and Name* Fields are required</font></center>");
        }
        exit("<script>document.getElementById('msg2').style.borderColor='red';</script><center><font color='FF0000'>Message* Field is required</font></center>");
    }

}
?>

修正を手伝ってください。何度も試しましたが、修正できません。私には難しすぎる

4

3 に答える 3

0

投稿変数でトリム関数を使用します。$nml = strlen(trim($_POST['name']));

于 2013-09-02T16:05:31.127 に答える
0

これを使って:

<?php

if(isset($_POST['sent'])) {

    $nml = strlen($_POST['name']);
    $eml = strlen($_POST['email']);
    $msgl = strlen($_POST['msg']);

    if(empty($nml)) { 
        echo "<script>document.getElementById('name2').style.borderColor='red'; </script><center><font color='red'>Name* fields is required</font></center><br>";
    }
    if(empty($eml)) {
        echo "<script>document.getElementById('email2').style.borderColor='red';</script><center><font color='red'>Email* fields is required</font></center><br>";
    }
    if(empty($msgl)) {   
        echo "<script>document.getElementById('msg2').style.borderColor='red'; <center><font color='red'>Message* field is required</font></center><br>";    
    }

    if(empty($nml) || empty($eml) || empty($msgl)) {
         exit;
    }
}

?>
于 2013-09-02T16:19:08.883 に答える