Welcome Guest, Not a member yet? Register   Sign In
Form Validation in a /folder/controller/method doesn't work?
#1

[eluser]dimas[/eluser]
Hi all,

I'm new to CodeIgniter and I'm stuck with a form validation problem. Until now I made some forms with validation using Form Validation library with no problems, but this one isn't working.

- I've the controller that call the view with the form (function new_product()) and save the data (function save_product()) in "controllers/user/products.php".
- The view with the form is in "views/user/products/new_product.php".
- The config for the validation is inside "config/form_validation.php".

If I move the controller to the parent directory (controllers/product.php) and update the form_open and the form_validation config the validation works!! But the same inside the controllers/user directory doesn't work. Do you know why??

My files resumed:

- Controller controllers/user/products.php -
Code:
public function new_product()
{
  $this->load->view('user/products/new_product');
}

public function save_product()
{
  $this->load->library('form_validation');
  if ($this->form_validation->run() === FALSE)
  {
    echo validation_errors(); // Only for testing. It only outputs something when the controller is in the main controllers folder, nothing inside controllers/user.
  }
  else
  {
    echo "ok!"; // Only for testing
  }
}

- Form view views/products/new_product.php -
Code:
...
<?php echo form_open('user/products/save_product'); ?>
...
<?php echo form_close(); ?>

- Configuration config/form_validation.php -
Code:
...
'user/products/save_product' => array(
        array(
        ....
...
#2

[eluser]Herlevsen[/eluser]
What uri are you calling the controller from? You do realise that you will have to include the folder in the uri right?

Code:
http://www.yoursite.com/user/product
#3

[eluser]TheFuzzy0ne[/eluser]
You mentioned that the file is named "product.php", but your URI says users/products (plural). Is that a typo?
#4

[eluser]dimas[/eluser]
[quote author="TheFuzzy0ne" date="1367513720"]You mentioned that the file is named "product.php", but your URI says users/products (plural). Is that a typo?[/quote]

Yes, it was an error writing the post, but the file is 'products.php', that's correct.

[quote author="Herlevsen" date="1367511272"]What uri are you calling the controller from? You do realise that you will have to include the folder in the uri right?[/quote]

See the files, I think the uri's are correct.
#5

[eluser]dimas[/eluser]
I've found the answer here: http://ellislab.com/forums/viewthread/151353/




Theme © iAndrew 2016 - Forum software by © MyBB