下記サイトを参考に問い合わせフォームを作成しているのですが、
リンク内容
確認ページで、フォームをすべて入力しても、
バリデートが上手くいっていないようで、送信ボタンが表示されません。
入力ページ
php
1 2<form id="mail-form" action="./check.php" method="post"> 3 <table> 4 <thead> 5 <tr> 6 <td colspan="2">コンタクトフォーム</td> 7 </tr> 8 </thead> 9 <tbody> 10 <tr> 11 <th>お名前</th> 12 <td><input type="text" class="required" id="name" name="name" value="" placeholder="名前を入力してください"> 13 <span class="error_required"></span> 14 <span class="error_name"></span> 15 </td> 16 </tr> 17 <tr> 18 <th>メールアドレス</th> 19 <td><input type="mail" class="required" id="email" name="email" value="" placeholder="メールアドレスを入力してください"> 20 <span class="error_required"></span> 21 <span class="error_email"></span></td> 22 </tr> 23 <tr> 24 <th>電話番号</th> 25 <td><input type="tel" class="required" id="tel" name="tel" value="" placeholder="電話番号を入力してください"> 26 <span class="error_tel"></span></td> 27 </tr> 28 <tr> 29 <th>お問い合わせ内容</th> 30 <td><textarea id="message" class="required" name="message" rows="5" cols="50"></textarea> 31 <span class="error_required"></span></td> 32 </tr> 33 </tbody> 34 <tfoot> 35 <tr> 36 <td><button type="reset" id="reset-input" name="reset-input">やり直す</button></td> 37 <td><button type="input-submit-check" value="" id="input-submit-check" name="input-submit-check">確認画面へ</button></td> 38 </tr> 39 </tfoot> 40 </table> 41</form>
確認ページ
php
1 2<?php 3 $postData = $_POST; 4 $page_flag = 0; 5 $error = array(); 6 function formValidation($postData) { 7 $error = array(); 8 if(empty($postData['name'])) { 9 $error[] = "お名前を入力してください"; 10 } else if(!preg_match('/^[ぁ-んァ-ヶー一-龠 \r\n\t]+$/',$postData['name'])) { 11 $error[] = "お名前は全角文字で入力してください"; 12 } 13 if(empty($postData['email'])) { 14 $error[] = "メールアドレスを入力してください"; 15 } else if(!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/',$postData['email'])) { 16 $error[] = "メールアドレスを正しく入力してください"; 17 } 18 if(empty($postData['tel'])) { 19 $error[] = "電話番号を入力してください"; 20 } else if(!preg_match('/^0\d{1,4}-\d{1,4}-\d{3,4}$/',$postData['tel'])) { 21 $error[] = "電話番号を正しく入力してください"; 22 } 23 if(empty($postData['messege'])) { 24 $error[] = "お問い合わせ詳細を入力してください"; 25 } else if(!preg_match('/^[ぁ-んァ-ヶー一-龠]+$/',$postData['messege'])) { 26 $error[] = "お問い合わせ内容は全角文字で入力してください"; 27 } 28 return $error; 29 } 30 $error = formValidation($postData); 31 if(empty($postData['input-submit-check']) || !empty($error)) { 32 $page_flag = 1; 33 } else { 34 $page_flag = 0; 35 } 36?> 37 38 39 40 41<form id="mail-form" action="./send.php" method="post"> 42<?php if($page_flag == 1): ?> 43<ul> 44 <?php foreach( $error as $value ): ?> 45 <li><?php echo $value; ?> 46 </li> 47 <?php endforeach; ?> 48</ul> 49<?php endif; ?> 50 <table> 51 <thead> 52 <tr> 53 <td colspan="2">入力内容確認</td> 54 </tr> 55 </thead> 56 <tbody> 57 <tr> 58 <th>お名前</th> 59 <td><?php echo htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8'); ?> 60 </td> 61 </tr> 62 <tr> 63 <th>メールアドレス</th> 64 <td><?php echo htmlspecialchars($_POST['email'], ENT_QUOTES, 'UTF-8'); ?> 65 </td> 66 </tr> 67 <tr> 68 <th>電話番号</th> 69 <td><?php echo htmlspecialchars($_POST['tel'], ENT_QUOTES, 'UTF-8'); ?> 70 </td> 71 </tr> 72 <tr> 73 <th>お問い合わせ内容</th> 74 <td><?php echo htmlspecialchars($_POST['message'], ENT_QUOTES, 'UTF-8'); ?> 75 </td> 76 </tr> 77 </tbody> 78 <tfoot> 79 <tr> 80 <td><a href="./form.php"><button type="button" id="back-input" name="back-input">入力画面へ戻る</button></a> 81 </td> 82 <td><?php 83 if($page_flag == 0) { 84 echo '<button type="submit" id="submit-send" name="submit-send">送信する</button>'; 85 } 86?> 87 </td> 88 </tr> 89 </tfoot> 90 </table> 91</form> 92 93 94 95
html冒頭formタグが切れてますので正しいものを提示してください
すいません、修正しました。
回答3件
あなたの回答
tips
プレビュー