Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cakephp中用户模型的验证错误未以自定义形式显示_Php_Cakephp_Cakephp 2.0 - Fatal编程技术网

cakephp中用户模型的验证错误未以自定义形式显示

cakephp中用户模型的验证错误未以自定义形式显示,php,cakephp,cakephp-2.0,Php,Cakephp,Cakephp 2.0,我尝试了stackoverflow的几种解决方案,但都不起作用。 我想在inputbox下面的表单中显示模型类中编写的错误消息 这是我的密码 we have created sign up form in html, but validation from model are not showing in form but if we create form in simple php as given in documentation validation are working. so ho

我尝试了stackoverflow的几种解决方案,但都不起作用。 我想在inputbox下面的表单中显示模型类中编写的错误消息

这是我的密码

we have created sign up form in html, but validation from model are not showing in form
but if we create form in simple php as given in documentation validation are working.
so how should we add custom validation from users model in signup form.

注册

用户名*

密码*

证实 密码*

电子邮件*

国家 选择国家

已经是会员了?

因此,请提出一些解决方案。
$errors=$this->User->validationErrors;添加到控制器中。

您需要迭代查看文件中的错误

尝试在控制器中添加以下内容:

 <div id="content">
  <!DOCTYPE html>
  <body>
   <?php echo $this->Session->flash('auth'); ?>
     <div class="container">
        <section>   
            <div id="container_demo" >       
              <div id="wrapper">
                 <div id="login" class="animate form">
             <form  action="/googleAtIntgeration/users/add" autocomplete="on" 
             method="post"> 
          <h1> Sign up </h1> 
         <div class ="flashmsg" ><?php echo $this->Session->flash(); ?></div>
         <p> 
      <label for="usernamesignup" class="uname" data-icon="u">Username<span 
        class="required">*</span></label>
       <input id="usernamesignup" name="data[User][username]" required="required" 
          type="text" placeholder="mysuperusername690" />
          </p> 
        <p <?php echo $this->Form->error('username') ?></p>
           <p> 
         <label for="password" class="youpasswd" data-icon="p">Password<span 
        class="required">*</span> </label>
        <input id="password" name="data[User][password]" required="required" 
         type="password" placeholder="eg. X8df!90EO" /> 
          </p>
        <p> <?php echo $this->Form->error('password') ?></p>
        <p> 
      <label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Confirm 
       Password<span class="required">*</span> </label>
        <input id="passwordsignup_confirm" name="data[User][confirm_password]" 
       required="required" type="password" placeholder="eg. X8df!90EO"/>
        </p>
       <p><?php echo $this->Form->error('confirm_password') ?></p>
        <p> 
        <label for="emailsignup" class="youmail" data-icon="e" >Email<span 
        class="required">*</span></label>
      <input id="emailsignup" name="data[User][email]" required="required" type="email" 
      placeholder="mysupermail@mail.com"/> 
       </p>
      <p> <?php echo $this->Form->error('email') ?></p>
        <p>
       <div class="input select"><label for="country">Country</label>
     <select name="data[User][country]" class="inputbox" id="country"><option 
      value="">Select Country</option>
      <?php echo $this->User->countryDropDown() ?>
     </select>
     </div>
      </p>
      <p class="signin button"> 
       <input type="submit" value="Sign up"/></p>
       <p class="change_link"> 
        Already a member ?
<a href="/googleAtIntgeration/users/login" class="to_register"> Go and log in </a>
        </p>
<input name="activity_code" type="hidden" value="REG"/>
                        </form>
                    </div>                  
                </div>
            </div>  
        </section>
        </div>
      </body>
      </html>   
     </div>

尝试在视图文件中的body标记(以.ctp结尾)之后添加以下内容:

<?php
    $errors = $this->User->validationErrors;
    $this->set('errors', $errors);
?>

这应该让你了解它是如何工作的

此外,请尝试参考以下问题/答案:


我强烈建议你停止操纵CakePHP,用“CakePHP方式”使用表单帮助程序——它们的存在是有原因的。起初,它们的使用令人望而生畏,毫无意义,但一旦您学会了如何使用它们,您就会发现它们节省了时间….

您能给我们一些您尝试过的代码吗?…谢谢,问题解决了。。。html表单在cakephp中不起作用,所以我使用并在cakephp文档中给出的php帮助下生成表单
<?php debug($errors); ?>