フォームで未入力チェックを書いたのですが、うまく作動しません。
入力していないのに送信を押すと送信されてしまいます。
どこがうまく行っていないかわからない状態です。
よろしくお願いいたします。
index.php
php
1session_start(); 2 3 4if (isset($_POST["submit"])){ 5 6 if(!$_POST['moji']) { 7 $errMsg = "★メッセージを入力して下さい<br>"; 8 exit(); 9} 10} 11$_SESSION['ticket'] = SHA1(uniqid().mt_rand()); 12 13if (isset($_POST['moji'])){ 14 $moji=$_POST['moji']; 15}else{ 16 $moji=""; 17} 18 19<!DOCTYPE HTML> 20<html> 21<head> 22 23<meta charset="utf-8"> 24<meta name="ROBOTS" content="NOINDEX"> 25<meta http-equiv="X-UA-Compatible" content="IE=edge"> 26<link rel="stylesheet" href="./common/css/global.css"> 27<link rel="stylesheet" href="./common/css/pure-drawer.css"> 28<meta name="viewport" content="width=device-width, initial-scale=1"> 29<script src="./common/js/userAgent_aPC.js" type="text/javascript"></script> 30<title>form</title> 31<style type="text/css"> 32</style> 33</head> 34 35<body id="a_patern"> 36<header id="a_header"> 37 38<div style="position:relative;"> 39<h1>form</h1> 40 41 42</div> 43 44</header> 45 46 47<div class="youtube"> 48<div> 49<iframe width="950" height="534" src="https://www.youtube.com/embed/<? 50if($no == "1"){echo "j6IBBuT1Ezs";} 51elseif($no == "2"){echo "TFVnZeXYt5M";} 52elseif($no == "3"){echo "vklrK49PguA";} 53elseif($no == "4"){echo "8YRoIUcNZwo";} 54 55else{ header("Location: ../"); 56?>?rel=0" frameborder="0" allowfullscreen></iframe> 57</div> 58</div> 59 60 61 62<div id="content_a" style="overflow:hidden;"> 63<a class="button" href="index.php?no=1">A</a> 64<a class="button" href="index.php?no=2">B</a> 65<a class="button" href="index.php?no=3">A</a> 66<a class="button" href="index.php?no=4">B</a> 67<br> 68<h2>ご意見やご要望をこちらに書き込んでください</h2> 69<h3>MESSAGE</h3> 70<form action="check.php" method="post" name="form"> 71 72 <p><textarea rows="20" name="moji" placeholder="ご意見・ご感想をご記入ください" style="margin:20px 0px 10px 0px;padding:3px;height:50px;width:300px;resize: none;" ></textarea></p> 73 <br> 74 <input type="hidden" name="ticket" value="<?php echo htmlspecialchars($_SESSION["ticket"], ENT_QUOTES);?>"> 75 <input type="submit" name="submit" class="submit" value="送信する"> 76 <?php if($errMsg) {echo "$errMsg";} ?> 77 </form> 78</body> 79</html>
check.php
php
1<?php 2 session_start(); 3 if(isset($_POST["submit"], $_SESSION["ticket"]) && $_SESSION["ticket"] == $_POST["ticket"]){ 4 unset($_SESSION["ticket"]); 5 6 }else{ 7 header('Location: index.php'); 8 exit(); 9 } 10 11if(isset($_POST['moji'])){ 12$moji=$_POST['moji']; 13} 14 15$ShiftJIS = array($_POST['moji'], date("Y年/m月/d日 H時i分s秒")); 16 mb_convert_variables('Shift_JIS', 'UTF-8', $ShiftJIS); 17 18 19 20$csv = fopen('text.csv', 'a+'); 21if (flock($csv, LOCK_EX)) { 22 23$content = fread($csv, filesize('text.csv')); 24 25ftruncate($csv, 0); 26 27rewind($csv); 28 29fputcsv($csv, $ShiftJIS); 30fwrite($csv, $content); 31 32flock($csv, LOCK_UN); 33} 34 35fclose($csv); 36 37 38 39exec("zip text.zip text.csv "); 40 41 42 43 44 mb_language("Japanese"); 45 mb_internal_encoding("UTF-8"); 46$filepath = "http://loyal-edit.com/tz/text.zip"; 47$boundary = "__BOUNDARY__"; 48 49$additional_headers = "Content-Type: multipart/mixed;boundary=\"" . $boundary . "\"\n"; 50$additional_headers .= "From:Message@yahoo.co.jp"; 51 52$message = "--" . $boundary . "\n"; 53 54$message .= "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n\n"; 55 56$message .= "http://loyal-edit.com/tz/text.zip\n"; 57$message .= "--" . $boundary . "\n"; 58 59$message .= "Content-Type: application/zip\n"; 60$message .= "Content-Disposition: attachment; filename=\"text.zip\n"; 61$message .= "Content-Transfer-Encoding: base64\n"; 62$message .= "\n"; 63$message .= chunk_split(base64_encode(file_get_contents('text.zip')))."\n"; 64 65$message .= "--" . $bound4ary . "--"; 66 67 68 69$to = "77709742@qq.com"; 70$subject = "Message"; 71$send_mail = mb_send_mail($to, $subject, $message, $additional_headers); 72 if ( $send_mail ) { 73 echo "投稿ありがとうございました!"; 74 echo nl2br("\n"); 75 echo nl2br("\n"); 76 echo '<a href="http://loyal-edit.com/dz/">戻る</a>'; 77 }else { 78 echo "メールを送信できませんでした。"; 79 80 } 81 82 83 84 ?>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/13 07:41
2017/02/13 07:53