如何在 drupal 中对自定义注册表单进行验证?
我在 drupal 6 中创建了自定义注册表单。我通过在主题中添加此代码来更改 drupal 注册页面的行为。模板文件
function earthen_theme($existing, $type, $theme, $path) {
return array(
// tell Drupal what template to use for the user register form
'user_register' => array(
'arguments' => array('form' => NULL),
'template' => 'user_register', // this is the name of the template
),
);
}
and my user_register.tpl.php file is looking like this...
<代码> //php标签从这里开始
$forms['access'] = array(
'#type'=> '字段集',
'#title'=> t('访问日志设置'),
);
$form['my_text_field']=array( '#type' => 'textfield',
'#default_value'=> $node->标题,
'#尺寸' => 30、
'#maxlength'=> 50、
'#required'=>正确
);
<div id="registration_form"><br>
<div class="field">
<?php
print drupal_render($form['my_text_field']); // prints the username field
?>
</div>
<div class="field">
<?php
print drupal_render($form['account']['name']); // prints the username field
?>
</div>
<div class="field">
<?php
print drupal_render($form['account']['pass']); // print the password field
?>
</div>
<div class="field">
<?php
print drupal_render($form['account']['email']); // print the password field
?>
</div>
<div class="field">
<?php
print drupal_render($form['submit']); // print the submit button
?>
</div>
</div>
如何对自定义的“my_text_field”进行验证。
我确实希望,一旦用户单击 my_text_field,则日期时间选择器应该打开,并且无论用户选择哪个日期,该日期都应该是 my_text_field 中的值。
所以大家帮忙。
预先感谢,
尼什
Panchjanya 公司
I have created custom registration form in drupal 6. i have used changed the behavior of the drupal registration page by adding this code in themes. template file
function earthen_theme($existing, $type, $theme, $path) {
return array(
// tell Drupal what template to use for the user register form
'user_register' => array(
'arguments' => array('form' => NULL),
'template' => 'user_register', // this is the name of the template
),
);
}
and
my user_register.tpl.php file is looking like this...
//php tag starts from here
$forms['access'] = array(
'#type' => 'fieldset',
'#title' => t('Access log settings'),
);
$form['my_text_field']=array( '#type' => 'textfield',
'#default_value' => $node->title,
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE
);
<div id="registration_form"><br>
<div class="field">
<?php
print drupal_render($form['my_text_field']); // prints the username field
?>
</div>
<div class="field">
<?php
print drupal_render($form['account']['name']); // prints the username field
?>
</div>
<div class="field">
<?php
print drupal_render($form['account']['pass']); // print the password field
?>
</div>
<div class="field">
<?php
print drupal_render($form['account']['email']); // print the password field
?>
</div>
<div class="field">
<?php
print drupal_render($form['submit']); // print the submit button
?>
</div>
</div>
How to make validation on "my_text_field" which is custmized.
and exactly i want that as soon as user click on my_text_field then datetime picker should be open and whichever date user select, that date should be value in my_text_field.
so guys help.
Thanks in advance,
nitish
Panchjanya Corporation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那绝对是错误的。
您应该使用 hook_form_alter() 来更改表单。它不属于主题层。
要实现自定义验证逻辑,请使用 #validate 回调< /a>.
That's absolutely wrong.
You should use hook_form_alter() to alter forms. It doesn't belong in the theming layer.
To implement custom validation logic, use a #validate callback.
真的吗?
有Drupal专家说你可以在主题中自定义表单。请参阅http://www.lullabot.com/articles/modifying-形式-drupal-5-和-6
Really?
There are Drupal experts who say you can customize the form in the theme. See http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6