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

时间:2010-04-28 11:31:52

标签: php javascript drupal-6 drupal-fapi user-registration

我在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
    ),
  );
}


<小时/> 和 我的user_register.tpl.php文件看起来像这样......

//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>

<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 Corporation

2 个答案:

答案 0 :(得分:2)

这是绝对错误的。

您应该使用hook_form_alter()来更改表单。它不属于主题层。

要实现自定义验证逻辑,请使用#validate callback

答案 1 :(得分:0)

真的?

有Drupal专家说你可以自定义主题中的表单。见http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6