/**
* Implementation of hook_form_alter().
*/
function ucenter_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_register_form':
// add a validator for user register.
$form['#validate'][] = 'your_register_validate'; //验证函数
break;
}
然后我们再写一个验证函数
function your_register_validate($form, &$form_state) {
//这里使用正则表达式,来验证网址的有效性,注意,这里的正则表达式,包围在"/...../"之间。
if(!preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $form_state['values']['email'])){
form_set_error('email',t('您输入的邮件地址格式不正确。'));
}
}
4 个回答
http://www.drupalla.com/#overlay=admin/config/people/accounts/fields 这里可以添加你需要的字段啊。
carterLv 9
链接打开跳到主页去了,,,看不到
loveye007Lv 6
Drupal 注册页的字段,可以在后台添加。地址是admin/config/people/accounts/fields
我们可以测试一下,添加一个字段叫drupalla,并且让其显示在注册表单。勾选Display on user registration form.
保存。然后回到注册页,发现多了一个textbox
默认注册表单的验证,是有必填,非必填。
而如果你要验证像邮箱是否格式正确之类的,就得通过 修改表单。修改表单,可以先右键审核元素。找到表单的id,注册表单的id是user-register-form。
我们新建一个模块叫drupalla,模块新建的教程请看用drupal 搭建一个传统留言版模块 1。
然后调用hook_form_alter,这个hook 是修改 form用的
然后我们再写一个验证函数
分头诗人Lv 17
当然要修改成你的网站的连接啊,如果你是本地的网站就改成 http://localhost/#overlay=admin/config/people/accounts/fields
carterLv 9