• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need your way of doing form validation

#1
[eluser]djuric[/eluser]
I need to do form validation, I even did something like this on one of the validation cases:

Code:
if($this->input->post('submitted') =='yes') { // this is hidden field in the form
    
if($this->form_validation->run() === TRUE) {
  $ovca['success'] = TRUE;
  $this->admin_model->update_duela($duel_id);
} else {
  $ovca['success'] = FALSE;
}
    
}

and in view like:

Code:
if($success) {
        echo "Your post has been submitted!";
} else {
        echo validatoin_errors();
}



Validation errors is great, I use it when validation fails. But when validation passes and form is submitted successfully, I usually do something like above.

Also, I could do something like this directly in view:

Code:
if($this->form_validation->run() === TRUE) {
   echo "Your post has been submitted!";
} else {
   echo validation_errors();
}

but it's not nice to do it in view. Is it?

Thanks for any suggestions


#2
[eluser]psychoder[/eluser]
you can pass your result to view and do the actions...


Code:
if($this->input->post('submitted') =='yes') { // this is hidden field in the form
    
if($this->form_validation->run() === TRUE) {
  $ovca = array('success'=>TRUE,'messages'=>'Your post has been submitted!');

  $this->admin_model->update_duela($duel_id);
} else {
  $ovca = array('success'=>FALSE,'messages'=>validation_errors());
}
  $this->load->view('your_view_file',$ovca);
}


then in your view... do it like this...

Code:
echo $message;

// or you can check the success before displaying the message...

if($success == TRUE)
{
//DO SOMETHING
}
else
{
  //DO SOMETHING
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.