Welcome Guest, Not a member yet? Register   Sign In
update form validation
#3

(This post was last modified: 05-28-2020, 08:04 AM by wdeda.)

(05-27-2020, 06:57 PM)rafapirapo Wrote: hello, I have a problem with select options, it is necessary that when entering the edit page, bring the selected item as it appears in the database, when the post is executed if there are validations errors return to the edit page but with the select option selected according to last choice of the user, example when entering the database the option FORD the user changes to VW and submits the form and does not pass the validation of other fields must return to the edition form with the selected VW option.---- MODEL
public function updaterecord($data)
    {
        $id = $data['UsuID'];
        return $this->where('UsuID', $id)
            ->set([
                'UsuLogin' =>  $data['UsuLogin'],
                'UsuNome' =>   $data['UsuNome'],
                'UsuCPF' =>    $data['UsuCPF'],
                'UsuNivel' =>  $data['UsuNivel'],
                'UsuStatus' => $data['UsuStatus']
            ])
            ->update();
    }----CONTROLE
public function update($id = NULL)
    {
        if ($this->request->getMethod() === 'post') {
            $data = $this->request->getPost();
            if($this->usuarioModel->updaterecord($data) == false){
                $session = session();
                $msgerrors = ['errors' => $this->usuarioModel->errors()];
                $session->setFlashdata($msgerrors, $data);
                return redirect()->back()->withInput();
            }
        }else{
            $data['dados'] = $this->usuarioModel->showid($id);
            echo view('includes/header');
            echo view('includes/menu');
            echo view('usuario_editar', $data);
            echo view('includes/footer');        }----VIEW<?php
              $v1=''; $v2 = '';
              if($dados[0]['UsuStatus'] === "0" || old('UsuStatus') === "0"){
                $v1 = 'selected';
              }else{
                $v1='';
              }
              if($dados[0]['UsuStatus'] === "1"  || old('UsuStatus') === "1"){
                $v2 = 'selected';
              }else{
                $v2='';
              }
          ?>
          <div class="form-group col-md-3 cb">
            <label for="cbusustatus">Ativo - Status</label>
            <select class="form-control" id="cbusustatus" name="UsuStatus">
              <option value="0"  <?php echo $v1 ?>>0-Sim </option>
              <option value="1" <?php echo $v2 ?>>1-Não </option>
            </select>
          </div>

I apologize, but I will use Portuguese to better understand what is going on, I have a slight idea.

Se entendi bem, você deseja que um usuário após não entrar com um campo obrigatório a tela mostrada seja a mesma em que este campo não é preenchido. Isso não é possível, mas, para tanto, basta o usuário retornar no navegador que a tela será exibida.

Com o código mostrado por você nada irá acontecer, pois não existe uma série de informaçãoes necessárias, não existe um formulário sequer para isso.

Por favor, não se ofenda, mas me permita lhe sugerir a leitura do manual https://codeigniter.com/user_guide/tutor...ction.html ou, acompanhar uma sequência de 4 vídeos no Youtube, em português, onde você irá encontrar exatamente o que deseja: https://www.youtube.com/watch?v=6e3KG8NrHOM

Boa sorte.
Reply


Messages In This Thread
update form validation - by rafapirapo - 05-27-2020, 06:57 PM
RE: update form validation - by nmaa3003 - 05-28-2020, 04:13 AM
RE: update form validation - by wdeda - 05-28-2020, 08:02 AM
RE: update form validation - by rafapirapo - 05-28-2020, 01:52 PM
RE: update form validation - by wdeda - 05-28-2020, 04:59 PM
RE: update form validation - by rafapirapo - 05-28-2020, 05:35 PM
RE: update form validation - by wdeda - 05-29-2020, 05:07 AM
RE: update form validation - by cukikt0302 - 05-28-2020, 10:12 AM
RE: update form validation - by InsiteFX - 05-29-2020, 03:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB