나는 마우스가 그 중 하나를 클릭 할 때까지 필드에 텍스트를 보여주는 HMTL 연락처 양식에서 자바 스크립트를 사용하려고합니다. 그러나 내 PHP는 여전히 필드에 텍스트가 있다는 것을 생각하는 것만 보입니다. JavaScript는 실제 HTML이 아닌 JavaScript입니다. 다른 사람이이 문제를 해결하도록 도와 줄 수 있습니까?내 javascript가 내 PHP를 혼란시키는 이유는 무엇입니까
자바 스크립트/HTML
<form method="post" action="sendEmail.php">
<input type="text" name="name" id="name" onfocus="if (this.value == 'Your Name')
this.value = '';" onblur="if (this.value == '') this.value = 'Your Name';" maxlength="30"
value="Your Name" />
<input type="text" name="email" id="email" onfocus="if (this.value == 'Your Email')
this.value = '';" onblur="if (this.value == '') this.value = 'Your Email';" maxlength="30"
value="Your Email" />
<br /><br />
<textarea name="message" id="comments" value="Enter Your Message Here..." cols="60" rows="5"
onfocus="if (this.value == 'Enter Your Message Here...') this.value = '';"
onblur="if (this.value == '') this.value = 'Enter Your Message Here...';" >Enter Your Message Here...</textarea>
</form>
PHP는
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+][email protected][a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 5) {
$error['comments'] = "Messages must be longer then 5 characters";
}
팁 : [프로그레시브 향상] (http://www.alistapart.com/articles/understandingprogressiveenhancement) 및 [구조, 표현 및 동작 분리] (http : //www.alistapart .com/articles/behaviorarnation) – Herbert