Welcome Guest, Not a member yet? Register   Sign In
Validation & Re-populating form & set_value() don't work
#1

[eluser]ReyPM[/eluser]
Hi every:
I'm trying to validate and repopulate a form but isn't working :grrr: This is the function that handles validation (not include all the fields because are a lot):
Code:
public function add() {
      $this->load->library('form_validation');
      
      $this->form_validation->set_rules('initial_inventory_91', isset($text_initital_inventory_91) ? $text_initital_inventory_91 : 'Inventario Inicial 91', 'trim|required|xss_clean');
      
      $this->form_validation->set_message('required', isset($text_error_required)?$text_error_required:'El campo %s es requerido');
      
      if($this->form_validation->run() == FALSE) {
         $this->load->view('trasegados/form');
      } else {
         redirect('embarcaciones/index'); //Registro de embarcaciones
      }
   }
And this is the HTML code (the same as before don't include all the fields):
Code:
<input class="form-txt" type="text" name="initial_inventory_91" id="initial_inventory_91" value="<?php echo isset($initial_inventory_91)?set_value($initial_inventory_91):'' ?>" />

But if the form contains errors never is populated with previous values, why? I've see this two post:
- http://ellislab.com/forums/viewthread/138002/
- http://ellislab.com/forums/viewthread/135367/
But didn't found the solution. Any help?
Cheers and thanks in advance ;-)
#2

[eluser]oppenheimer[/eluser]
First, in your view, I think it should be:
Code:
<input class="form-txt" type="text" name="initial_inventory_91" id="initial_inventory_91" value="<?php echo set_value('initial_inventory_91');?>" />

Second, in your controller I think your set_rules should be:

Code:
$this->form_validation->set_rules('initial_inventory_91','Inventario Inicial 91', 'trim|required|xss_clean');
#3

[eluser]Nisha S.[/eluser]
There is no need for the isset checking. Just put your only your rules in Controller. set_value function accepts default value as one of the paramter, you can use it instead of using isset. If need more help you can refer it from my blog.




Theme © iAndrew 2016 - Forum software by © MyBB