1

gentel_idモデルに次の検証ルールを持つフィールドがありますContrat

public $validate = array(
    'gentel_id' => array(
        'numeric' => array(
            'rule' => 'numeric',
            'required' => true,
            'allowEmpty' => false,
            'message' => 'Veuillez entrer un identifiant GENTEL ou mettre la valeur 0000000000',
        ),
    ),
);

私のコントローラーで:

    public function add($id = null) { 
      if ($this->request->is('post')) {

      $this->Contrat->create();

      if ($this->Contrat->save($this->request->data)) {

        $this->Session->setFlash(__('Le Contrat a été ajouté'));
        $this->redirect(array('action' => 'edit', $this->Contrat->getInsertID() ));
      } else {
        debug($this->Contrat->validationErrors);
        $this->Session->setFlash(__('Le Contrat ne peut être ajouté'));
      }
    $this->set('id',$id);
    ...
    }

私のフォームでは:

    <?php echo $this->Form->create('Contrat');?>
            <?php                           
                        if (empty($id)){
                            echo $this->Form->input('client_id',array('empty' => "Client non défini",'default' => $id, 'onchange'=>"window.location.href= '/contrats/add/'+this.form.ContratClientId.options[this.form.ContratClientId.selectedIndex].value"));
                        }else{
                            echo "<span class=\"label\">".__('Client')."</span>".$this->Kaldom->link(h($clients[$id]),array('controller' => 'clients', 'action' => 'view',$id));
                            echo $this->Form->input('client_id', array('type' => 'hidden','value' => $id));
                        }
            echo $this->Form->input('gentel_id',array('type'=>'text','label'=> 'Gentel ID'));
                ?>
    <?php echo $this->Form->end(__('Créer'));?>

「gentel_id」を空にしてフォームを保存しようとすると、保存が正しく行われず、デバッグ ( $this->Contrat->validationErrors) で次のようになります。

Array
(
    [gentel_id] => Array
    (
        [0] => Veuillez entrer un identifiant GENTEL ou mettre la valeur 0000000000
    )

)

しかし、エラーメッセージはフォームに表示されません。これは add 関数ですが、次のように URL にパラメーターを渡していることに注意してください: .../contrats/add/3

助けてください。

4

0 に答える 0