Form_validation isn't using rules from config file (CI2) |
[eluser]kirkaracha[/eluser]
My form validation isn't using the rules in a config file in CodeIgniter 2. I'm accessing the form at /admin/people/add and /admin/people/edit/id and submitting to /admin/people/save. When I submit the add form it just reloads add without reporting any validation errors (my form views will display validation errors if $this->form_validation->_error_array is not empty; this is working on my login form). When I submit the edit form I get a 404 error at /admin/people/save even though that URI works with add. application/config/form_validation.php: Code: <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); application/controllers/admin/people.php: Code: public function add() { application/views/add_edit_person_form.php: Code: <?php
[eluser]InsiteFX[/eluser]
Try this: Also make sure you are loading the Form_Validation libray! Code: public function save() InsiteFX
[eluser]kirkaracha[/eluser]
I get the same results. I'm loading the form validation library in the constructor: Code: public function __construct() {
[eluser]Cristian Gilè[/eluser]
Quote: } else { Do you want to redirect in the admin area or outside? It should be: Code: } else { to redirect in the admin area. Cristian Gilè
[eluser]kirkaracha[/eluser]
Where it's redirecting isn't the problem. The problem is I submit the add form without a required field and it isn't being caught by the validation. The same validation rules work if I include them in my controller. Code: // added to save function above:
[eluser]Cristian Gilè[/eluser]
The array index should be admin/people/save but.... https://bitbucket.org/ellislab/codeignit...ocate-rule Cristian Gilè
[eluser]Chimpski[/eluser]
I was able to get it to work by using in the controller: $this->form_validation->set_rules($this->config->item('validation_rule_name', 'form_validation')); |
Welcome Guest, Not a member yet? Register Sign In |