formmail사용 중 checkbox를 필수로 선택하게 하고 싶습니다.
본문
<form name="contactForm" id="contactForm" action="php/contact.php" method="POST" autocomplete="off" class="clearfix">
<div id="contactForm_form" class="contactform">
<div class="tbl_frm tbl_wrap">
<ul>
<li class="clearfix">
<span class="mail-g">E-MAIL</span>
<label for="contact_email" class="sound-only">이메일 *</label>
<input type="email" class="frm_input full_input required" id="contact_email" name="contact_email" title="Email" placeholder="E-MAIL">
</li>
<li class="clearfix">
<span class="mail-g">MESSAGE</span>
<label for="contact_message" class="sound-only">내용 *</label>
<textarea id="contact_message" name="contact_message" rows="10" title="Message" placeholder="MESSAGE"></textarea>
</li>
</ul>
<div id="contactForm_term">
<fieldset class="contactForm_agree">
<label for="agree_check">메일 회신을 목적으로 한 개인정보제공에 동의합니다.</label>
<input type="checkbox" name="agree_check" value="" id="agree_check" class="required">
</fieldset>
</div>
<div class="btn_confirm">
<input id="contact_submit" type="submit" class="btn_submit" value="SEND MAIL">
</div>
</div>
</div>
</form>
<?php
session_start();
@ini_set('display_errors', 0);
@ini_set('track_errors', 0);
@date_default_timezone_set('Europe/Bucharest'); // Used only to avoid annoying warnings.
if($_REQUEST['action'] = 'email_send') {
// BEGIN
require('config.inc.php');
$array['contact_email'] = isset($_REQUEST['contact_email']) ? strip_tags(trim($_REQUEST['contact_email'])) : '';
$array['contact_message'] = isset($_REQUEST['contact_message']) ? trim(strip_tags($_REQUEST['contact_message'], '<b><a><strong>')) : '';
$array['agree_check'] = isset($_REQUEST['agree_check']) ? strip_tags(trim($_REQUEST['agree_check'])) : '';
// Check email
if(ckmail($array['contact_email']) === false)
die('_invalid_email_');
// Check required fields
if($array['contact_email'] == '' || $array['contact_message'] == ''|| $array['agree_check'] == '')
die('_required_');
// Optional - if completed!
$PHONE = ($array['contact_phone'] != '') ? "<b>Phone:</b> {$array['contact_phone']} <br>" : null;
$SUBJECT = ($array['contact_subject'] != '') ? "<b>Subject:</b> {$array['contact_subject']} <br>" : null;
$mail_body = "
<b>Date:</b> {$date} <br>
<b>Name:</b> {$array['contact_name']} <br>
<b>Email:</b> {$array['contact_email']} <br>
{$PHONE}
{$SUBJECT}
<b>Message:</b> {$array['contact_message']} <br>
--------------------------------------------------- <br>
IP: {$ip}
";
// @SEND MAIL
if($m->Send()) {
die('_sent_ok_');
} else {
die($m->ErrorInfo);
}
unset($array, $m);
}
// mail()
else {
mail(
$config['send_to'] ,
$array['contact_subject'],
$mail_body
);
}
}
이렇게 구성했는데, 저 agree_check 이름을 가진 체크박스를 체크해도 넘어가지 않아요.
스크립트로 값을 읽어줘야한다고 하는데 스크립트를 넣어도 읽기만 하고 계속 required만 뜨네요ㅠㅠ 어디를 어떻게 고쳐야할까요?ㅠㅠ
도와주세여 절실합니다...
!-->!-->답변 2
var checked = $('#agree_check').is(':checked');
if(checked) { alert("동의하지 하였습니다.";
} else { alert("동의하지 않았습니다."; }
위의 내용을 추가해 보세요
input agree_check에 value를 ""이 아닌 1, true 등 값을 주셔야 하지 않을까요
""일 경우라면 체크되면 [""], 안되면 [] 이런느낌인듯...
답변을 작성하시기 전에 로그인 해주세요.