CodeIgniter Forums
Error 404 if I put a helper form or error in forms - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Error 404 if I put a helper form or error in forms (/showthread.php?tid=28760)



Error 404 if I put a helper form or error in forms - El Forum - 03-20-2010

[eluser]Distriker[/eluser]
Hello, I am new and very interesting user in CodeIgniter and I already a tutorial, and try with little codes, but, now I try created the system of the oficial webpage of my applications.

Now I am try put a register and login system, but I have two errors.

First, I say the errors and then I put the code.

1º I had download the Redux Auth and my problem is when I access to the view. The view show this error:
Code:
Fatal error: Call to undefined function form_open() in /var/www/codei/system/application/views/usuarios/registrarse.php on line 6
In this line, I have the form_open, I am trying change the code but I don't have solution. If I remove the form_open, the error is in the form_input, and continue so if I remove each one and jump the error in the other input.

2º A friend says me that I must put the helper form in the code of the controller or in the view, but, if i put the helper, the webpage says me a Error 404. I don't understand because this happens.

I have the next code:

Controller, usuarios/registrarse.php
Code:
<?php
                
class Registrarse extends Controller
{
    function registrarse ()
    {
          parent::Controller() ;

        $this->load->helper('form');

        // Required Field Rules.
        $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['password2']     = "required";
        $rules['email']         = "required";
        $rules['question']     = "required";
        $rules['answer']         = "required";
        
                $this->load->library('validation');
        $this->validation->set_rules($rules);
        
        // Required Field Names
        $fields['username']     = "Username";
        $fields['password']     = "Password";
        $fields['password2']     = "Repeat Password";
        $fields['email']         = "Email Address";
        $fields['question']        = "Secret Question";
        $fields['answer']        = "Secret Answer";
        
        $this->validation->set_fields($fields);
            
        if ($this->validation->run())
        {
            // Validation Passed
            
            $redux = $this->redux_auth->register
            (
                $this->input->post('username'),
                $this->input->post('password'),
                $this->input->post('email'),
                $this->input->post('question'),
                $this->input->post('answer')
            );
            
            // The reason we put the method into a variable is so we can deal
            // with the different return messages.
            
            // I use a switch statement to deal with the different return
            // messages produced by the registration method.
            
            switch ($redux) {
                case 'REGISTRATION_SUCCESS':
                    # code...
                    break;
                case 'REGISTRATION_SUCCESS_EMAIL':
                    # code...
                    break;
                case false:
                    # code...
                    break;
                case true:
                    # code...
                    break;
            }
        }
        else
        {
            $this->load->view("usuarios/registrarse");
        }
    }
}

View, usuarios/registrarse.php
Code:
<h1>Registration</h1>

&lt;?php echo $this->validation->error_string; ?&gt;
&lt;?php echo form_open('usuarios/registrarse'); ?&gt;


    <label for="username">Username : </label>
    &lt;?php echo form_input('username'); ?&gt;
    
    <label for="password">Password : </label>
    &lt;?php echo form_password('password'); ?&gt;
    
    <label for="password2">Repeat Password : </label>
    &lt;?php echo form_password('password2'); ?&gt;
    
    <label for="email">Email : </label>
    &lt;?php echo form_input('email'); ?&gt;
    
    <label for="question">Secret Question : </label>
    &lt;?php echo form_input('question'); ?&gt;
    
    <label for="answer">Answer : </label>
    &lt;?php echo form_input('answer'); ?&gt;
    
    <label for="submit"> </label>
    &lt;?php echo form_submit('submit', 'Register Now'); ?&gt;

&lt;?php echo form_close(); ?&gt;
</div>

Do you need a other file? Say me please.

I am from Spain, and my English isn't perfect, but I try speak English for resolve my problem.

Thanks for read so far.

Greetings, Distriker


Error 404 if I put a helper form or error in forms - El Forum - 03-20-2010

[eluser]dejitaru[/eluser]
I think It may be a problem of syntaxis because the combination of php4 and php5. If u are using php4, change the name of the method registrarse for-> Registrarse with uppercase R and create a separate method for what u are doing:

class Registrarse extends Controller
{

function Registrarse()
{
parent::Controller() ;

$this->load->helper('form');
}
function registro(){
// Required Field Rules.
$rules['username'] = "required";
$rules['password'] = "required";
$rules['password2'] = "required";
$rules['email'] = "required";
$rules['question'] = "required";
$rules['answer'] = "required";

$this->load->library('validation');
$this->validation->set_rules($rules);

// Required Field Names
$fields['username'] = "Username";
$fields['password'] = "Password";
$fields['password2'] = "Repeat Password";
$fields['email'] = "Email Address";
$fields['question'] = "Secret Question";
$fields['answer'] = "Secret Answer";

$this->validation->set_fields($fields);

if ($this->validation->run())
{
// Validation Passed

$redux = $this->redux_auth->register
(
$this->input->post('username'),
$this->input->post('password'),
$this->input->post('email'),
$this->input->post('question'),
$this->input->post('answer')
);

// The reason we put the method into a variable is so we can deal
// with the different return messages.

// I use a switch statement to deal with the different return
// messages produced by the registration method.

switch ($redux) {
case 'REGISTRATION_SUCCESS':
# code...
break;
case 'REGISTRATION_SUCCESS_EMAIL':
# code...
break;
case false:
# code...
break;
case true:
# code...
break;
} //end of switch
}
else
{
$this->load->view("usuarios/registrarse");
}
}
}


Error 404 if I put a helper form or error in forms - El Forum - 03-21-2010

[eluser]Distriker[/eluser]
I believe that I am using PHP5, but I tryed to put in different methods that you say but continue saying me:

Code:
&lt;?php
                
class Registrarse extends Controller
{
  function Registrarse()
  {
      parent::Controller() ;

      $this->load->helper('form');
  }
         function registro() {

        // Required Field Rules.
        $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['password2']     = "required";
        $rules['email']         = "required";
        $rules['question']     = "required";
        $rules['answer']         = "required";
        
                $this->load->library('validation');
        $this->validation->set_rules($rules);
        
        // Required Field Names
        $fields['username']     = "Username";
        $fields['password']     = "Password";
        $fields['password2']     = "Repeat Password";
        $fields['email']         = "Email Address";
        $fields['question']        = "Secret Question";
        $fields['answer']        = "Secret Answer";
        
        $this->validation->set_fields($fields);
            
        if ($this->validation->run())
        {
            // Validation Passed
            
            $redux = $this->redux_auth->register
            (
                $this->input->post('username'),
                $this->input->post('password'),
                $this->input->post('email'),
                $this->input->post('question'),
                $this->input->post('answer')
            );
            
            // The reason we put the method into a variable is so we can deal
            // with the different return messages.
            
            // I use a switch statement to deal with the different return
            // messages produced by the registration method.
            
            switch ($redux) {
                case 'REGISTRATION_SUCCESS':
                    # code...
                    break;
                case 'REGISTRATION_SUCCESS_EMAIL':
                    # code...
                    break;
                case false:
                    # code...
                    break;
                case true:
                    # code...
                    break;
            }
        }
        else
        {
            $this->load->view("usuarios/registrarse");
        }
    }
}

?&gt;

Where is the problem?

Greetings


Error 404 if I put a helper form or error in forms - El Forum - 03-21-2010

[eluser]InsiteFX[/eluser]
Code:
1) You should be using an associate Array!

$config = array(
               array(
                     'field'   => 'username',
                     'label'   => 'Username',
                     'rules'   => 'required'
                  );

2) Your if statement should be like below.

if ($this->form_validation->run() == FALSE)
{
    $this->load->view('myform');
}
else
{
    $this->load->view('formsuccess');
}

3) There is no method in the validation library
   called set_fields

Also you make an method/function for you validation etc...

I think you need to re-read the users guide

Enjoy
InsitteFX


Error 404 if I put a helper form or error in forms - El Forum - 03-21-2010

[eluser]Distriker[/eluser]
But, I don't understand, the controller that I put here is the controller default that have the Redux Auth.

Quote:3) There is no method in the validation library called set_fields

What? Do you say that here: $this->validation->set_fields($fields); - I must put a other method? Althoug, it's so:

Code:
I believe that I am using PHP5, but I tryed to put in different methods that you say but continue saying me:
&lt;?php
                
class Registrarse extends Controller
{
  function Registrarse()
  {
      parent::Controller() ;

      $this->load->helper('form');
  }
         function registro() {

        // Required Field Rules.
        $rules['username']    = "required";
        $rules['password']    = "required";
        $rules['password2']     = "required";
        $rules['email']         = "required";
        $rules['question']     = "required";
        $rules['answer']         = "required";
        
                $this->load->library('validation');
        $this->validation->set_rules($rules);
        
        // Required Field Names
        $fields['username']     = "Username";
        $fields['password']     = "Password";
        $fields['password2']     = "Repeat Password";
        $fields['email']         = "Email Address";
        $fields['question']        = "Secret Question";
        $fields['answer']        = "Secret Answer";

        }

         function validation() {
        
        $this->validation->set_fields($fields);
        
        }
            
        if ($this->validation->run())
        {
            // Validation Passed
            
            $redux = $this->redux_auth->register
            (
                $this->input->post('username'),
                $this->input->post('password'),
                $this->input->post('email'),
                $this->input->post('question'),
                $this->input->post('answer')
            );
            
            // The reason we put the method into a variable is so we can deal
            // with the different return messages.
            
            // I use a switch statement to deal with the different return
            // messages produced by the registration method.
            
            switch ($redux) {
                case 'REGISTRATION_SUCCESS':
                    # code...
                    break;
                case 'REGISTRATION_SUCCESS_EMAIL':
                    # code...
                    break;
                case false:
                    # code...
                    break;
                case true:
                    # code...
                    break;
            }
        }
        else
        {
            $this->load->view("usuarios/registrarse");
        }
    }
}

?&gt;

Greetings


Error 404 if I put a helper form or error in forms - El Forum - 03-23-2010

[eluser]dejitaru[/eluser]
The form_open() in your view must be form_open('usuarios/registrarse/registro') if u are using the code I gave u. thats why is giving u a 404 not found. Its not finding your controller.


Error 404 if I put a helper form or error in forms - El Forum - 03-23-2010

[eluser]Distriker[/eluser]
Thanks, I already haven't got problems Wink

Thanks for alls Wink

Greetings