<div class="panel panel-success"> <div class="panel-heading">註冊</div> <div class="panel-body"> <form class="form-horizontal" action="index.php" method="post" role="form"> <div class="form-group"> <label class="col-md-4 control-label" for="email">Email:</label> <div class="col-md-8"> <input type="text" name="email" id="email" placeholder="請輸入Email" class="form-control"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label" for="pass">密碼:</label> <div class="col-md-8"> <input type="text" name="pass" id="pass" placeholder="請設定密碼" class="form-control"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label" for="name">姓名:</label> <div class="col-md-8"> <input type="text" name="name" id="name" placeholder="請輸入中文姓名" class="form-control"> </div> </div> <div class="text-center"> <button type="submit" name="op" value="save_regist" class="btn btn-primary">確定註冊</button> </div> </form> </div> </div>
其中,密碼改為明碼,避免使用者輸入錯誤。或者也可以改成輸入兩次密碼,然後進行比對亦可(只是比較麻煩)。
另外,記得設定 op,以便告訴程式下一步要做什麼。
當然原本的登入表單 templates\side_login.tpl 也要改一下帳號部份,另外,還得加上註冊的連結:
<div class="panel panel-primary"> <div class="panel-heading">登入</div> <div class="panel-body"> <form class="form-horizontal" action="index.php" method="post" role="form"> <div class="form-group"> <label class="col-md-4 control-label" for="email">Email:</label> <div class="col-md-8"> <input type="text" name="email" id="email" placeholder="請輸入Email" class="form-control"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label" for="pass">密碼:</label> <div class="col-md-8"> <input type="password" name="pass" id="pass" placeholder="請輸入密碼" class="form-control"> </div> </div> <div class="text-center"> <input type="hidden" name="op" value="login"> <a href="index.php?op=regist" class="btn btn-success">註冊</a> <button type="submit" name="button" class="btn btn-primary">登入</button> </div> </form> </div> </div>
case 'regist': break;
{if $op=='regist'} {include file='regist_form.tpl'} {else} {$content} {/if}
問題是,index.tpl如何取得 $op 變數?當然得由index.php傳給他!所以,修改 index.php,多傳一個 $smarty->assign('op', $op); 到樣板。
require_once 'smarty/libs/Smarty.class.php'; $smarty = new Smarty; $smarty->assign('name', $name); $smarty->assign('group', $group); $smarty->assign('content', $content); $smarty->assign('op', $op); $smarty->assign('page_title', '活動報名系統'); $smarty->display('index.tpl');