###実現したいこと
クラス内のif文の判定でelseになった際に出る"正しく入力されていません"のメッセージを
smartyのテンプレートで表示させたいです
###発生している問題
画面にメッセージが表示されない
###該当のソースコード
PHP
1<?php 2require_once('db_connection.php'); 3 4class User_registaration extends Db_Connection 5{ 6 public function __construct() 7 { 8 parent::__construct(); 9 } 10 11 //ユーザ情報登録 12 public function user_registaration($name, $pass) 13 { 14 $sql = "INSERT INTO ip_d_user_information(infouser_user_name, infouser_password) VALUES (?, ?)"; 15 $stmt = $this->link->prepare($sql); 16 $stmt->execute(array($name, password_hash($pass, PASSWORD_DEFAULT))); 17 } 18 19 //名前重複チェック 20 public function user_duplication($name) 21 { 22 $sql = "SELECT * FROM ip_d_user_information"; 23 //SQL文実行 24 $stmt = $this->link->query($sql); 25 try 26 { 27 while($item = $stmt->fetch()) 28 { 29 if($name == $item['infouser_user_name']) 30 { 31 throw new Exception('入力されたユーザ名は既に使われています'); 32 } 33 } 34 }catch(Exception $e) 35 { 36 $_SESSION["error"] = $e->getMessage(); 37 } 38 } 39} 40 41$username = $_POST["username"]; 42$password = $_POST["password"]; 43$password2 = $_POST["password2"]; 44 45$user = new User_registaration; 46 47$user->user_duplication($username); 48 49$user->user_registaration($username, $password);
PHP
1<?php 2 3require_once('Smarty.class.php'); 4require_once('../file_class/login_authentication.php'); 5require_once('../file_class/user_registration.php'); 6 7$smarty = new Smarty(); 8 9$smarty->template_dir = '../templates'; 10$smarty->compile_dir = '../templates_c'; 11$smarty->config_dir = '../configs/'; 12$smarty->cache_dir = '../cache/'; 13 14session_start(); 15 16// メッセージの初期化 17$errorMessage = ""; 18$signUpMessage = ""; 19 20$smarty->assign(signUpError, $_SESSION["error"]); 21 22$smarty->display('signup.tpl');
tpl
1{config_load file="layout.conf"} 2 3{$smarty.config.head} {* ヘッドの呼出 *} 4 5<script type="text/javascript" src="js/signup.js" charset="UTF-8"> 6</script> 7 8<body> 9 10<div id="contents"> 11 <h1>新規ユーザ登録</h1> 12 <form id="loginForm" name="loginForm" action="signup.php" method="POST"> 13 <table> 14 <tr> 15 <div class="error">{$signUpError}{$dbError}</div> 16 <div class="input success">{$signUpMessage}</div> 17 <td><label for="username">ユーザ名</label></td> 18 <td><input type="text" id="signusername" name="username"> 19 <p class="f-xs mt5">ユーザ名は5~20文字の範囲で入力してください</p></td> 20 </tr> 21 <br> 22 <tr> 23 <td><label for="password">パスワード</label></td> 24 <td><input type="password" id="signpassword" name="password" value=""> 25 <p class="f-xs mt5">パスワードは8~16文字の範囲で入力してください</p></td> 26 </tr> 27 <br> 28 <tr> 29 <td><label for="password2">パスワード(確認用)</label></td> 30 <td><input type="password" id="signpassword2" name="password2" value=""> 31 <p class="f-xs mt5">パスワードは8~16文字の範囲で入力してください</p></td> 32 </tr> 33 </table> 34 <br> 35 <button class="signup_btn" type="submit" id="confirm" name="confirm">入力内容確認</button> 36 <button class="signup_btn" type="submit" id="signUp" name="signUp">登録</button> 37 </form> 38</div> 39</body> 40</html> 41 42
そもそもクラス内で$smarty->assign('signUpError', $errorMessage);を記述しても意味がないのでしょうか
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/16 23:49