【问题标题】:Why is my form_validation not working ? error : Field form are not correctly filled为什么我的 form_validation 不起作用?错误:未正确填写字段表单
【发布时间】:2020-03-12 09:11:10
【问题描述】:

我正在使用CodeIgniter 记录的用户信息使用预填表格更新个人资料信息。

我的问题是,无论我在表单中输入什么,prebuild 函数form_validation->run() 返回true,这意味着表单字段没有正确填写。 我认为这与我的数据库无关。

这是我的看法:

<form action="http://obiwan2.univ-brest.fr/licence/lic85/V1/CodeIgniter/index.php/vendeur/modifier_profil_vendeur" method="post">
    <div class="form-group">
        <label for="uname">Prénom:</label>
        <?php echo'<input type="text" class="form-control" id="cmpt_prenom" placeholder="Entrez votre prenom" name="cmpt_prenom" value="'.$profil_vendeur->Prf_prenom.'">';?>
    </div>
    <div class="form-group">
        <label for="uname">Nom:</label>
        <?php echo'<input type="text" class="form-control" id="cmpt_nom" placeholder="Entrez votre nom" name="cmpt_nom" value="'.$profil_vendeur->Prf_nom.'">';?>
    </div>
    <div class="form-group">
        <label for="uname">adresse e-mail:</label>
        <?php echo'<input type="email" class="form-control" id="cmpt_email" placeholder="Entrez votre e-mail" name="cmpt_email" value="'.$profil_vendeur->Prf_mail.'">';?>
    </div>
    <div class="form-group">
        <label for="pwd">Mot de passe:</label>
        <input type="password" class="form-control" id="mdp" placeholder="Entrez votre mot de passe" name="mdp">
    </div>
    <div class="form-group">
        <label for="pwd">Confirmation du mot de passe:</label>
        <input type="password" class="form-control" id="conf_mdp" placeholder="Confirmez votre mot de passe" name="conf_mdp">
    </div>
    <button type="submit" class="btn btn-success">Valider</button>
</form>

这是我正在使用的控制器功能:

if ($this->form_validation->run() == FALSE) {
    if ($mdp1==$mdp2) {
        $this->db_model->update_prf_nom_prenom_mail_vendeur($prenom,$nom,$mail,$mdp1);
    } else {
        $mdp['mdp']=$this->db_model->get_prf_nom_prenom_mail();
        $this->db_model->update_prf_nom_prenom_mail_vendeur($prenom,$nom,$mail,$mdp['mdp']->Cmpt_mdp);
    }
} else {
    if ($this->session->statut=="V") {
        $data['profil_vendeur']=$this->db_model->get_prf_nom_prenom_mail();
        $this->load->view('templates/vendeur_haut');
        echo("Veuillez remplir au moins les champs : Prénom, nom, mail");
        $this->load->view('vendeur_modifications_compte.php',$data);
        $this->load->view('templates/bas');
    }
}

感谢您花时间帮助我解决此问题。

【问题讨论】:

    标签: php html database forms codeigniter


    【解决方案1】:

    试试这个。请在控制器部分添加 $this->form_validation->set_rules。

    $this->form_validation->set_rules('cmpt_prenom', 'cmpt_prenom', 'required');
    $this->form_validation->set_rules('cmpt_nom', 'cmpt_nom', 'required');
    $this->form_validation->set_rules('cmpt_email', 'cmpt_email', 'required');
    $this->form_validation->set_rules('mdp', 'mdp', 'required');
    $this->form_validation->set_rules('conf_mdp', 'conf_mdp', 'required');
    
    if ($this->form_validation->run() == FALSE) {
        if ($mdp1==$mdp2) {
            $this->db_model->update_prf_nom_prenom_mail_vendeur($prenom,$nom,$mail,$mdp1);
        } else {
            $mdp['mdp']=$this->db_model->get_prf_nom_prenom_mail();
            $this->db_model->update_prf_nom_prenom_mail_vendeur($prenom,$nom,$mail,$mdp['mdp']->Cmpt_mdp);
        }
    } else {
        if ($this->session->statut=="V") {
            $data['profil_vendeur']=$this->db_model->get_prf_nom_prenom_mail();
            $this->load->view('templates/vendeur_haut');
            echo("Veuillez remplir au moins les champs : Prénom, nom, mail");
            $this->load->view('vendeur_modifications_compte.php',$data);
            $this->load->view('templates/bas');
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多