名前 [必須]

メール [必須]

電話番号 [必須]

件名 [必須]

お問い合わせ内容 [必須]

個人情報の取扱い

送信して頂いた情報は、お問い合わ
せへの回答のためのみ使用し、その
他の目的で使用したり、無断で第三
者へ提供することはございません。


php file iconPHP

        
<?php
$title='PHP Valitron';
$rootUrl='../../';
include $rootUrl.'head.php'; 

// valitronのバリデーション
require_once ('vendor/autoload.php');

$v = new Valitron\Validator($_POST);

// インプットテキストのエラー設定とエラーメッセージの設定
// エラー設定されていると該当するものすべてが表示される
$v->rule('required', ['postName', 'postMail', 'postTel', 'postSubject', 'postContents'])->message(
  '※{field}が空です。'
);
$v->rule('email', 'postMail')->message(
  '※{field}の形式が合ってません。'
);
$v->rule('length', ['postName', 'postTel', 'postSubject'], 20)->message(
  '※{field}の文字列は20字以内です。'
);
$v->rule('numeric', 'postTel')->message(
  '※{field}は数字のみです。'
);
$v->rule('length', 'postContents', 500)->message(
  '※{field}は500文字以内です。');

// 日本語化
$v->labels(array('postName' => '氏名', 'postMail' => 'メールアドレス', 'postTel' => '電話番号', 'postSubject' => '件名', 'postContents' => 'お問い合わせ内容'));

// if($v->validate()){
//   echo 'エラーはありません。';
// }else{
//   foreach($v->errors() as $error){
//     foreach($error as $value){
//       echo $value;
//     }
//   }
// }

?>
        
      

html file iconHTML

        
        <!-- index.php -->
  <div class="card-right">
    <!-- バリデーションの表示 -->
    <?php if(!$v->validate()): ?>
      <ul class="error_list">
        <?php foreach($v->errors() as $error): ?>
          <li><?php echo implode($error); ?></li>
        <?php endforeach; ?>
      </ul>
    <?php endif; ?>
  
    <form method="post" id="variForm">
      <p>名前 <span>[必須]</span></p>
      <input type="text" name="postName" id="postName" placeholder="氏名" 
      value="<?php if (isset($postName)) { echo $postName;} ?>" required>
      
      <p>メール <span>[必須]</span></p>
      <input type="mail" name="postMail" id="postMail" placeholder="example@mail.com" 
      value="<?php if (isset($postMail)) { echo $postMail;} ?>" required>

      <p>電話番号 <span>[必須]</span></p>
      <input type="tel" name="postTel" id="postTel" placeholder="0123456789" 
      value="<?php if (isset($postTel)) { echo $postTel;} ?>" required>

      <p>件名 <span>[必須]</span></p>
      <input type="text" name="postSubject" id="postSubject" placeholder="質問・依頼・その他" 
      value="<?php if (isset($postSubject)) { echo $postSubject;} ?>" required>

      <p>お問い合わせ内容 <span>[必須]</span></p>
      <textarea name="postContents" id="postContents" cols="32" rows="14" placeholder="内容..." required>
        <?php if (isset($postContents)) { echo $postContents;} ?></textarea>

      <fieldset>
        <legend>個人情報の取扱い</legend>
        <p>送信して頂いた情報は、お問い合わ<br>せへの回答のためのみ使用し、その<br>他の目的で使用したり、無断で第三<br>者へ提供することはございません。</p>
        <div class="checkie">
          <input type="checkbox" name="checkbox" id="checkBox" onclick="checkOn()" aria-label="認証チェック">
          <button type="submit" name="submit" value="入力内容を確認する" id="nextBtn" disabled>同意して入力内容を確認する</button>
        </div>
      </fieldset>
    </form>
  </div>
        
      

css file iconCSS

      
.card-right{
  display:flex;
  flex-direction: column;
  align-items: center;
  padding:60px 0;
}
.card-right .error_list {
  list-style-type: none;
  text-align: left;
  padding-left: 0;
  width: 400px;
}
.card-right .error_list li {
  padding: 8px;
  color: salmon;
  font-size: 1rem;
  border: 1px solid salmon;
  border-radius: 8px;
  margin-bottom: 8px;
}
.card-right form {
  text-align: left;
  width: 340px;
  margin-left:32px;
}    
.card-right form p {
  font-size: 1.1rem;
  margin:0;
}
.card-right form p span {
  color: salmon;
}
    
.card-right form input {
  width: 340px;
  line-height: 1.7;
  font-size: 1.2rem;
  margin-bottom: 0.8rem;
}

.card-right form input[type=checkbox] {
  transform: scale(2);
  margin: 16px 0;
  width:30px;
}

.card-right form textarea {
  font-size: 1rem;
}
    
.card-right form button {
  margin-top: 16px;
  font-size: 1.1rem;
  padding: 0.3rem 1.5rem;
  border: 2px solid gray;
  outline: none;
  border-radius: 0.3rem;
  color: grey;
  transition: 0.4s ease;

}