Welcome Guest, Not a member yet? Register   Sign In
problem with form validation
#1

[eluser]elmne[/eluser]
I have encountered a problem.

when i implement the following controller


Code:
<?php
class Customertype extends Controller {

    function index()
    {
        echo 'Hello World!';
    }
    
    
    function customertype_add()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('customer_type', 'Customer Type', 'required');
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('admin/customertype_add');
        }
        else
        {
               $this->load->model('Customertype_class','',TRUE);  // TRUE autoconnects model to database
                $this->Customertype_class->add_customertype();
               $this->load->view('admin/customertype_added');
        }

    }
    

    
    
}
?>



and i have this form to submit to the controller

Code:
</head>

<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

  <p>&nbsp;</p>
  <p>Customer Type:
    &lt;input type="text" name="customer_type" /&gt;
  </p>
  <p>
    &lt;input type="submit" name="submit" value="Submit" /&gt;
  </p>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

I get the following error when i run the form


Quote:localhost/xxxx/index.php/form.html

404 Page Not Found

The page you requested was not found.


The controller is in admin folder controllers/admin/customertype.php

The view is in the view folder views/admin/customertype_add.php


I then access the controller at

Quote:localhost/xxxx/index.php?admin/customertype/customertype_add

But when i click "submit", it brings up the url

Quote: localhost/xxxx/index.php/form.html


and then the error message "Not Found"

What's the cause of this?
#2

[eluser]WanWizard[/eluser]
As per the manual: the open_form() helper has the URI of your page as parameter. In your example, you use 'form', which correctly translates to 'index.php?form.html'.

In this case, you should probably use open_form('admin/customertype'), which is the controller you want to load.
#3

[eluser]elmne[/eluser]
Thanks, that solved the problem




Theme © iAndrew 2016 - Forum software by © MyBB