如何在 drupal 中对自定义注册表单进行验证?

发布于 2024-08-30 13:28:19 字数 1930 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沩ん囻菔务 2024-09-06 13:28:19

那绝对是错误的。

您应该使用 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.

那小子欠揍 2024-09-06 13:28:19

真的吗?

有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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文