Welcome Guest, Not a member yet? Register   Sign In
trying to understand form_validation
#5

[eluser]pickupman[/eluser]
Code:
if ($this->form_validation->run() == FALSE)
{
    $this->load->view('comment_view'); //renders page
}
else  // form submit below here!
{
    $this->db->insert('comments', $_POST);
      
    redirect('myBlog/comments/'.$entry_id);
    // $this->comment_insert();
    $this->load->view('myBlog/comments/'.$entry_id); //renders page
}

Form validation works by creating your validation rules, that will be processed by form
Code:
$this->form_validation->set_rules('field_name', 'field name', 'required');

You then need a block of code that checks whether the validation rules have been satisfied.
Code:
if($this->form_validation->run() == FALSE){
  //The form failed. Try reloading the form here again
}else{
  //The form was successful. May want to add this to the DB or redirect to another page.
}

Another helpful feature of form validation is using the set_value() function. You can repopulate the fields that a user typed, and when the form fails, the values they did fill out will be added back into the fields
Code:
<input name="some_field" type="text" size="10" value="<?php echo set_value('some_field', 'default value');?> " />


Messages In This Thread
trying to understand form_validation - by El Forum - 07-02-2010, 01:39 PM
trying to understand form_validation - by El Forum - 07-02-2010, 08:33 PM
trying to understand form_validation - by El Forum - 07-03-2010, 05:38 AM
trying to understand form_validation - by El Forum - 07-03-2010, 06:43 AM
trying to understand form_validation - by El Forum - 07-03-2010, 11:31 AM
trying to understand form_validation - by El Forum - 07-03-2010, 12:28 PM
trying to understand form_validation - by El Forum - 07-03-2010, 04:08 PM
trying to understand form_validation - by El Forum - 07-04-2010, 07:45 AM
trying to understand form_validation - by El Forum - 07-04-2010, 08:05 AM
trying to understand form_validation - by El Forum - 07-04-2010, 08:15 AM
trying to understand form_validation - by El Forum - 07-04-2010, 11:02 AM
trying to understand form_validation - by El Forum - 07-04-2010, 11:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB