いつもお世話になっております。
教材をこなし、いざ自分でValidationのロジックを書いているのですが、
思い通りにinputが空の時に表示するエラーが表示できません。
何時間も格闘していますが、何を書き間違えているのか、
ロジックが抜けているのかさっぱりです。
どなたかご指摘とアドバイスをよろしくお願いします。
php
1<?php 2 3error_reporting(E_ALL); 4ini_set('display_errors', 'On'); 5 6if (!empty($_POST)) { 7 8 $error_msg = array(); 9 10 define('MSG01', '入力必須です。'); 11 12 if (empty($_POST['email'])) { 13 echo "email"; 14 $error_msg['email'] = MSG01; 15 } 16} 17?> 18 19<!doctype html> 20<html lang="jp"> 21<head> 22 <meta charset="UTF-8"> 23 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 24 <link rel="stylesheet" href="style.css"> 25 <title>Document</title> 26</head> 27<body> 28<div class="body-wrapper row"> 29 <div class="container"></div> 30 <div class="col-md-4"></div> 31 <div class="col-md-4"> 32 <form method="post"> 33 <fieldset class="form-group"> 34 <legend> 35 <h1>input something</h1> 36 </legend> 37 <span class="error-msg"> 38 /*ここのエラー表示されない*/ 39 <?php if (isset($error_msg['email'])) echo $error_msg['email']; ?> 40 </span> 41 <input type="text" name="email" class="form-control" placeholder="Email"> 42 <button type="submit" class="btn btn-success">ログイン</button> 43 </fieldset> 44 </form> 45 </div> 46 <div class="col-md-4"></div> 47</div> 48</body> 49</html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。