构建CakePHP注册页面

时间:2011-06-30 01:15:48

标签: error-handling cakephp-1.3

我有一个网站,我希望用户注册到特定的群组。要访问该组,您需要知道他们的组织ID和组织密码。

我正在尝试创建一个表单,允许我验证组ID和密码是否存在且是否正确,然后创建一个新用户。我想验证用户表单中的所有字段,如果它们不起作用,可以自动错误地打印错误。

具有讽刺意味的是,当我“烘焙”我的应用程序时,它会创建成功显示错误消息的表单。但是出于某些原因,我无法用自定义表单打印出任何验证错误。

我这样做的方式是:

<div class="full center">
        <?
            echo $this->Session->flash();
            echo $this->Session->flash('auth');
        ?>
        <h3>Organization ID / Registration Code</h3>
        <?php 
            echo $this->Form->create('User', array('action'=>'register_user'));
            echo $this->Form->input('Organization.id', array('type'=>'text', 'label' => 'Organization ID'));
            echo $this->Form->input('Organization.registration_code', array('label' => 'Organization Registration Code')); ?>
        <h3>User Account Information </h3>
        <?php
            echo $this->Form->input('User.email');
            echo $this->Form->input('User.password', array('value'=>''));
            echo $this->Form->input('User.name');
            echo $this->Form->input('User.xxxx');
            echo $this->Form->input('User.xxxx');
            echo $this->Form->input('User.xxxx');
            echo $this->Form->input('User.xxxx');
        ?>
        <div><input type="checkbox" name="data[tos][agree]"> I agree to the Terms of Service.</div>
        <div><input type="checkbox" name="data[pp][agree]"> I agree to the Privacy Policy.</div>
        <?php echo $this->Form->end(__('Join my Organization', true));?>
</div>

但没有任何效果!如果这是构建此类注册表单的正确方法以及如何显示错误,请告知我们。

此外,我需要一个类似的注册页面,我将同时接收用户信息和组织信息,然后创建组织和用户并将用户添加到组织。如何构建?

谢谢!

1 个答案:

答案 0 :(得分:1)

<div class="full center">
    <?
        if($session->check('Message.flash')) 
      { 
        echo $this->Session->flash();
        echo $this->Session->flash('auth');
       }
    ?>
    <h3>Organization ID / Registration Code</h3>
    <?php 
        echo $this->Form->create('User', array('action'=>'register_user'));
        echo $this->Form->input('Organization.id', array('type'=>'text', 'label' => 'Organization ID'));
        echo $this->Form->input('Organization.registration_code', array('label' => 'Organization Registration Code')); ?>
    <h3>User Account Information </h3>
    <?php
        echo $this->Form->input('User.email');
        echo $this->Form->input('User.password', array('value'=>''));
        echo $this->Form->input('User.name');
        echo $this->Form->input('User.xxxx');
        echo $this->Form->input('User.xxxx');
        echo $this->Form->input('User.xxxx');
        echo $this->Form->input('User.xxxx');
    ?>
    <div><input type="checkbox" name="data[tos][agree]"> I agree to the Terms of Service.</div>
    <div><input type="checkbox" name="data[pp][agree]"> I agree to the Privacy Policy.</div>
    <?php echo $this->Form->end(__('Join my Organization', true));?>

相关问题