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

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>
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