为什么我的form_validation无法正常工作?错误:字段表单未正确填写

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

我的问题是,无论我放置在表单中什么,预构建函数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,$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');
    }
}

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

solabc 回答:为什么我的form_validation无法正常工作?错误:字段表单未正确填写

尝试一下。请在控制器部分添加$ 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,$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');
    }
}
本文链接:https://www.f2er.com/3090480.html

大家都在问