我正在创建一个下拉选择选项的注册表单。注册表为:
名称:电子邮件:密码:学校:(下拉选项列表)我设置了两个表,一个叫"用户",另一个叫"学校"。在我的"users"表中,列是"id"(int(11))
、"email"(varchar(255)
、"name"(varchar(64)
和"school"(varchar(64))。在我的"schools"表中,列是"id"(int(11))、"users_id"(int(11))和"school_id"(int(11))"。我不确定这张表的设置是否正确,所以请告诉我是否有更好的设置方法。我做了"school_id",因为我以后也会有一个搜索系统,用户可以在其中搜索特定学校的人。
<form action="register.php" method="post">
<div class="field">
<label for="email">Email:</label>
<input type="email" id="email" value="" autocomplete="on" action="" />
</div>
<div class="field">
<label for="password">Password:</label><br />
<input type="password" id="password" autocomplete="off" />
</div>
<div class="field">
<label for="name">Name:</label><br />
<input type="text" id="name" action="" />
</div>
<div class="field">
<label for="school">School:</label>
<select id="school" size="1">
<option value="a">Apple School</option>
<option value="b">Banana School</option>
<option value="c">Carrot School</option>
</select>
</div>
<input name="Register" type="submit" id="register" value="" />
</form>
And my register.php:
<?php
require_once 'core/init.php';
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'email' => array(
'required' => true,
'min' => 2,
'max' => 255,
'unique' => 'users'
),
'password' => array(
'required' => true,
'min' => 6
),
'name' => array(
'required' => true,
'min' => 2,
'max' => 50
),
//I don't know how to put the school drop down in here)
));
if($validation->passed()) {
$user = new User();
$salt = Hash::salt(32);
try {
$user->create(array(
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'name' => Input::get('name'),
'school' => Input::get('school'),
'joined' => date('Y-m-d H:i:s'),
));
Session::flash('home', 'You have been registered and can now log in!');
Redirect::to('index.php');
} catch(Exception $e) {
die($e->getMessage());
}
} else {
foreach($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}?>
如果有其他方法,请帮助我。我通过phpacademy的OOP登录/注册教程找到了这种方法。
我认为你应该把你的表格改成这种格式
用户表 "id"(int(11))
, "email"(varchar(255)
, "name"(varchar(64)
, "school_id"(int(11))
"id"(int(11))
、"school_id"(int(11))"
、"school_name"(varchar(255))
现在您可以访问学校表,将下拉列表放到您的代码中。