Probleme sur le validate Cakephp 2

Par Corentin, il y a 14 ans


Bonjour c'est encore moi ...

Alors la maintenant un problème se pose mes règles de validation ne passe pas ...

Voici mon Model user.php

var $validate = array(
    'username' => array(
             "rule" => array('custom', '/\S+/'),
             "message" => "Vous devez saisir un titre."

    ));

Voici mon Controller UsersController.php

public function inscription() {

        if($this->request->is('post')){

            if($this->User->validates()){
                // debug($this->request->data);
            }

        }

        $data'title_for_layout'] = 'Inscription';
        $this->set($data);
    }

Aucune erreur s'affiche malgré la condition ...

EDIT : J'ai regarde le tuto de grafikart sa fais exactement pareil les règles de validations ne s'applique pas ...

Merci par avance

9 réponses

JeremyJones, il y a 14 ans

Tu peux me montrer ton formulaire. Ton regex est-il valide? As tu essayé avec une rule basique, du genre alphanumeric?

Corentin, il y a 14 ans

Bonjour,

Oui mon regex est valide car je l'utiliser avant, même les autre fonctions sa passe pas

Voici le code de ma view : ->

<?php //echo $this->Form->create('User'); ?>
<table>

<tr>
<td>
<?php echo $this->Html->image("devtool/joueur.png", array('class'=>'icon_text'));?> Nom de compte :
</td>
<td>
<?php echo $this->Form->input('username',array('label'=>'','style'=>'margin-top:4px;margin-bottom:4px')); ?>
</td>
</tr>
<tr>
<td>
<?php echo $this->Html->image("devtool/construction.png", array('class'=>'icon_text'));?> Mot de passe : 
</td>
<td>
<?php echo $this->Form->input('password',array('label'=>'','style'=>'margin-top:4px;margin-bottom:4px')); ?>
</td>
</tr>
<tr>
<td>
<?php echo $this->Html->image("devtool/construction.png", array('class'=>'icon_text'));?> Confirmez votre mot de passe : 
</td>
<td>
<?php echo $this->Form->input('password_confirm',array('label'=>'','style'=>'margin-top:4px;margin-bottom:4px')); ?>
</td>
</tr>
<tr>
<td>
<?php echo $this->Html->image("devtool/user.png", array('class'=>'icon_text'));?> Pseudo : 
</td>
<td>
<?php echo $this->Form->input('pseudo',array('label'=>'','style'=>'margin-top:4px;margin-bottom:4px')); ?>
</td>
</tr>

<tr>
<td>
<?php echo $this->Html->image("devtool/email_open.png", array('class'=>'icon_text'));?> Adresse E-mail : 
</td>
<td>
<?php echo $this->Form->input('email',array('label'=>'','style'=>'margin-top:4px;margin-bottom:4px')); ?>
</td>
</tr>

<tr>
<td>
<?php echo $this->Html->image("devtool/config.png", array('class'=>'icon_text'));?> Question secrète :
</td>
<td>
<?php
$choix_quest=array(
           'Nom de ma boisson préféré :'=>'Nom de ma boisson préféré :',
           'Nom de mon acteur favori :'=>'Nom de mon acteur favori :',
           'Nom de mon grand-père :'=>'Nom de mon grand-père :',
           'Le premier travail de ma mère :'=>'Le premier travail de ma mère :',
           'Lieu de naissance de mon père :'=>'Lieu de naissance de mon père :',
           'Ma chanson favorite :'=>'Ma chanson favorite :',
           'La marque de mon Pc :'=>'La marque de mon Pc :');
echo $this->Form->select('pos_questy',$choix_quest, array('style'=>'margin-top:4px;margin-bottom:4px'))
?>
</td>
</tr>

<tr>
<td>
<?php echo $this->Html->image("devtool/config.png", array('class'=>'icon_text'));?> Réponse secrète :
</td>
<td>
<?php echo $this->Form->input('rep_quest',array('label'=>'','style'=>'margin-top:4px;margin-bottom:4px')); ?>
</td>
</tr>

<tr>
<td>
<?php echo $this->Html->image("devtool/error.png", array('class'=>'icon_text'));?> Conditions générales d'utilisation :
</td>
<td>
<?php echo $this->Form->checkbox('cgu',array('style'=> 'width:16px;margin-top:4px;margin-bottom:4px;')); ?><?php echo $this->Html->image("devtool/help.png", array('style'=> 'width:16px;margin-top:4px;margin-left:9px;margin-bottom:4px;','class'=>'icon_text', 'title'=> 'Attention, lire attentivement & accepter les C.G.U !'));?>
</td>
</tr>

<tr>
<td>
</td>
<td>
<?php echo $this->Form->end('Inscription !'); ?>
</td>
</tr>

</table>

Merci par avance
Corentin

JeremyJones, il y a 14 ans

Heu normal

<?php //echo $this->Form->create('User'); ?>

???

Laurent., il y a 14 ans

Si tu ne créé pas le formulaire, ça risque pas de marcher :)

Corentin, il y a 14 ans

Bonjour,

J'ai oublier de mettre cette ligne

<?php echo $this->Form->create("User",array("url"=>array("controller"=>"users","action"=>"inscription"))); ?>

quand j'ai copier mon code, mais j'ai toujours rien ...

JeremyJones, il y a 14 ans

Bizarre tu n'as besoin de lui indiquer l'url/controller/et/compagnies, si ton formulaire ce situe dans la page inscription,

<?php echo $this->Form->create('User');?>

Cela suffira.

Corentin, il y a 14 ans

oui mais le soucis ça règle pas non plus mon problème c'est vraiment le bordel cakephp 2 :(

Grafikart, il y a 14 ans

Tu as oublier surtout tu faire un set pour envoyer les données dans le controller avant le validates
$this->User->set($this->request->data);
if(.....

Corentin, il y a 14 ans

Quel con de moi x')

Merci Grafikart ;)