새로고침시 다시 전송되는 폼메일...
본문
잘 작동되는 폼메일 플러그인을 찾았는데..
이게 원래 새창에 뜨는 폼메일이고 제출 버튼 누를시 새창이 꺼지는 형식입니다..
그런데 전 메인에 바로 넣고 싶어서 넣었더니
새로고침할때마다 입력했던 양식으로 계속 전송되네요ㅜㅜ
플러그인의 index.php 소스 첨부합니다..
<?php
define('_INDEX_', true);
include_once('./_common.php');
include_once(G5_PATH."/lib/mailer.lib.php");
//ver1.0 161114 @_9173543234
$to = '아이디@naver.com'; //받을메일주소
//구글 리캡차 : https://www.google.com/recaptcha/
$recaptcha_site_key = '';
$recaptcha_secret_key = '';
$sz_table = 'sz_contactus'; //게시판
$sz_contactus_table = $g5['write_prefix'].$sz_table;
@include_once('./create_db.php');
function sz_contact_us_insert_write($insert)
{
global $g5;
$bo_table = $insert['bo_table'];
$write_table = $g5['write_prefix'].$bo_table;
$wr_num = get_next_num($write_table);
$wr_subject = addslashes(trim($insert['wr_subject']));
$wr_content = addslashes(trim($insert['wr_content']));
$sql = " insert into $write_table
set wr_num = '$wr_num',
wr_option = 'html1,,',
wr_subject = '$wr_subject',
wr_content = '$wr_content',
mb_id = '".rand()."',
wr_name = '".rand()."',
wr_datetime = '".G5_TIME_YMDHIS."',
wr_last = '".G5_TIME_YMDHIS."',
wr_ip = '{$_SERVER['REMOTE_ADDR']}' ";
sql_query($sql);
$wr_id = sql_insert_id();
sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");
sql_query(" update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$bo_table}' ");
return $wr_id;
}
if ($_POST['mode']=='w')
{
if (!$_POST['name'] or !$_POST['email'] or !$_POST['phone'] or !$_POST['message']) die('Err');
if (isset($_POST['g-recaptcha-response']))
$captcha = $_POST['g-recaptcha-response'];
if (!$captcha)
alert('스팸차단코드가 틀렸습니다.');
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array('secret' => $recaptcha_secret_key, 'response' => $captcha);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, sizeof($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
if ($obj->success!=1) die('Err');
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = conv_content(trim($_POST['message']), 2);
$strsub = '상담 문의'.$name;
$strcon = '<p>아래 링크에서 확인하세요.</p>
<p> </p>
<p>상담 정보:<br>
이름: '.$name.'<br>
이메일주소: '.$email.'<br>
연락처: '.$phone.'<br>
메시지: '.$message.'</p>';
$insert = array(
'bo_table' => $sz_table,
'wr_subject' => $strsub,
'wr_content' => $strcon
);
$sz_id = sz_contact_us_insert_write($insert);
$href = G5_BBS_URL.'/board.php?bo_table='.$sz_table.'&wr_id='.$sz_id;
$strbody = "<p>아래 링크에서 확인하세요.</p>
<p> </p>
<p><a target='_blank' href='".$href."'>".$href."</a></p>";
mailer($name, '*** 개인정보보호를 위한 이메일주소 노출방지 ***', $to, $strsub, $strbody, 1);
$str = $name.'님의 상담이 접수되었습니다.';
echo '<script>';
echo 'alert("'.$str.'");';
echo 'opener.document.location.reload();';
echo 'window.close();';
echo '</script>';
}
include_once('./_head.php');
add_stylesheet('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">', 0);
add_stylesheet('<link rel="stylesheet" href="'.G5_PLUGIN_URL.'/sz_contact_us/style.css">', 1);
?>
<div class="container">
<h2><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> CONTACT US</h2>
<form class="form-horizontal" method="post" action="./index.php" onsubmit="return fsubmit(this);">
<input type="hidden" name="mode" value="w" />
<blockquote>
<p>이용하시면서 불편한 사항이나 개선점이 있다면 언제든지 알려주세요.<br>이메일을 함께 남겨주시면, 답변을 받아 보실 수 있습니다.</p>
</blockquote>
<div class="form-group">
<label class="col-sm-2 control-label">이름</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">이메일</label>
<div class="col-sm-10">
<input type="email" class="form-control" placeholder="Your Email *" id="email" name="email" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">연락처</label>
<div class="col-sm-10">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" name="phone" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">문의사항</label>
<div class="col-sm-10">
<textarea class="form-control" placeholder="Your Message *" id="message" name="message" rows="5" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">자동등록방지</label>
<div class="col-sm-10">
<div class="g-recaptcha" data-sitekey="<?php echo $recaptcha_site_key; ?>"></div>
</div>
</div>
<div class="col-lg-12 text-center" style="padding-top:20px">
<div id="success"></div>
<button type="submit" class="btn btn-xl">Send Message</button>
</div>
</form>
</div>
<script>
function fsubmit(f)
{
return true;
}
</script>
<script src='https://www.google.com/recaptcha/api.js?hl=ko'></script>
<?php
include_once('./_tail.php');
?>
붉은색 부분을 고쳐야 하나 해봤지만 잘 안되네요..
검색해보니 onclick 형식으로 바꾸면 된다던데..? 어찌해야할지 모르겠습니다ㅠㅠ
답변 2
index.php에 저렇게 코드를 넣는 것은 좋지않습니다
(메일을 보내지 않아도 필요없이 mailer.lib.php를 include하니까요)
빨강색 부분 삭제 후 아래처럼 바꾸고
alert("{$name}님의 상담이 접수되었습니다.", index.php");
메일 발송부분을 따로 떼어서 send_mail.php화일로 만들고
action을 변경하세요
<form action="send_mail.php"~~
$str = $name.'님의 상담이 접수되었습니다.';
echo '<script>';
echo 'alert("'.$str.'");';
echo 'opener.document.location.reload();';
echo 'window.close();';
echo '</script>';
초록색 부분을
echo 'location.href = '/';
이렇게 바꾸시면 경고창이 한 번 뜨고 페이지가 새로 고침이 일어납니다.
이게 싫으시면 php 코드들 몽땅 잘라내서 php 파일 하나 만드셔서 거기에 넣으세요.
그리고 <form ~~~ action="위에서 만드신 파일.php"> 이렇게 바꾸시면 됩니다.